标签:
1、与数据库连接的步骤:
1)加载驱动程序
Class.forname("com.microsoft.sqlserver.jdbc.SQLServerDriver");//SQLServer 2000
2)创建数据库URL
String url = "jdbc:mysql"; //localhost:3306/myDB
String user = "MyUserName";
String password = "MYPWD";
3)建立连接
Connection conn = DriverManager.getConnection(url,user,password);
4)关闭连接
stmt.close();//有访问语句即需要
conn.close();
在4)之前可以增加数据访问语句
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuert("SELECT *FROM student");
标签:
原文地址:http://www.cnblogs.com/cailingsunny/p/4881373.html