日期:2014-05-20 浏览次数:20855 次
try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); System.out.println("加载:com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } Connection conn = null; Statement st = null; ResultSet rs = null; try { System.out.println("获取连接..."); conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1533;databaseName=test", "sa", "admini"); System.out.println("连接获取完毕"); st = conn.createStatement(); System.out.println("st"); rs = st.executeQuery("select id from test"); System.out.println(rs); while(rs.next()){ System.out.println(rs.getString("id")); } } catch (SQLException e) { e.printStackTrace(); }finally{ try { rs.close(); st.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } }