访问sqlserver2005 数据库
下面代码有问题吗?
try {
String url="jdbc:sqlserver://localhost:1433;DatabaseName=myPeople";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String USER = "sa";
String PASSWORD = " ";
Connection conn=DriverManager.getConnection(url,USER,PASSWORD);
String sql="select * from people";
PreparedStatement pstmt=conn.prepareStatement(sql);
ResultSet rs=pstmt.executeQuery();
while (rs.next()) {
System.out.println(rs.getString(2));
}
} catch (
ClassNotFoundException e) {
e.printStackTrace();
} catch (
SQLException e) {
e.printStackTrace();
}
------解决方案--------------------JDK 的问题吧!!!
------解决方案--------------------有没有完整的代码?
这里你没有关闭conn、pstmt、rs最好在catch之后加入finally语句块 然后把这些都close掉