SqlServer2008

第一个SqlServer2008程序

    数据库的连接:

实验的准备:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 
 
  <body>
  <% Connection con;
  Statement sql;
  ResultSet rs;
  try{
  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  }
 
  catch(Exception e){
  out.print(e);
  }
 
  try{
  String uri="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=Student";
  String user="sa";
  String password="sasa";
  con=DriverManager.getConnection(uri,user,password);
  sql=con.createStatement();
  rs=sql.executeQuery("select * from score where _math>80");
  out.print("<table border=2>");
  out.print("<tr>");
  out.print("<th width=100>"+"_id");
  out.print("<th width=100>"+"_name");
  out.print("<th width=50>"+"_english");
  out.print("<th width=50>"+"_math");
  out.print("<th width=50>"+"_php");
  out.print("</tr>");

  while(rs.next()){
  out.print("<tr>");
  out.print("<td>"+rs.getString(1)+"</td>");
  out.print("<td>"+rs.getString(2)+"</td>");
  out.print("<td>" +rs.getFloat("_english")+ "</td>");
  out.print("<td>" +rs.getFloat("_math")+ "</td>");
  out.print("<td>" +rs.getFloat("_php")+ "</td>");
  out.print("</tr>");
  }
  out.print("</table>");
  con.close();
  }
  catch(SQLException e1){
  out.print(e1);
  } 
   %>
  </body>
</html>

本实验的结果:

SqlServer2008_第1张图片

本实验前的准备:

Student下建立Score表:

SqlServer2008_第2张图片



你可能感兴趣的:(数据库,sqlserver,sqlserver2008)