//PreparedStatement
PreparedStatement ps=null;
Connection ct=null;
ResultSet rs=null;
try{
//初始化对象
//加载驱动
Class.forName("com.microsoft.jdbc.SQLServerDriver");
//2、得到连接
ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=student","sa","123");
//创建jdbc
ps=ct.prepareStatement("select * from stu");
//执行,,如果是增删改,用excuteUpdate,,,如果是查询使用excuteQuery
rs=ps.executeQuery();
//循环取出
while(rs.next())
{
//
rs.getString(1);
//
rs.getString(3);
System.out.println(rs.getString(1)+" "+rs.getString(3));
}
}catch(Exception e){
e.printStackTrace();
}finally{
//关闭连接………………
}