qq_23947943
qq_23947943
2016-08-03 07:30

jsp jdbc方式连接SQL sever 操作数据库时没有返回的数据

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

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



连接SQL Server数据库


<%
Connection conn = null;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Hsjy1";
String user = "sa";
String password = "12345678";
conn = DriverManager.getConnection(url,user,password);
Statement st = conn.createStatement();

out.println("取得连接");
out.println("测试1");
out.println(conn.toString());
ResultSet rs = st.executeQuery("SELECT * FROM Hsjy1.dbo.dibu");
out.println("测试2");
while(rs.next()){

out.println("测试3");
out.println(rs.getString("Tel")+rs.getString("Fax")+rs.getString("beian"));
        }
        out.println("测试4");
        rs.close();
       conn.close();
       out.println("测试5");
     %>
</body>

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答