import java.sql.*;
public class test012 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String url = "jdbc:sqlserver://localhost:64690; DatabaseName=test";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
Statement st;
Connection con;
try {
Class.forName(driver);// 加载驱动
System.out.println("驱动加载成功!");
} catch (ClassNotFoundException event) {
System.out.print("无法创建驱动程式实体!");
}
try {
con = DriverManager.getConnection(url, "sa", "sa123456");
con.setAutoCommit(true);
System.out.println("已经连接到数据库...");
st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * from a ");
System.out.println("id"+" "+"date");
while (rs.next()) {
String id = rs.getString("id");
String date = rs.getString("date");
System.out.println(id+""+date);
}
st.close();
con.close();
} catch (SQLException e1) {
System.out.println("异常" + e1);
}
}
} |