jdbc的使用步骤
1、加载驱动类
2、建立连接
3、执行SQL
4、遍历结果集
5、释放连接
以下代码均为自习练习,连接自己的数据库,对表进行简单的查询,删除操作,其中还有PreparedStatement的一个小练习。代码如下:
@Test
public void testPreparedDelete(){
/*
* 写的不是太规范,没有关闭资源
*/
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/hibernate3","root","123");
public void testPreparedDelete(){
/*
* 写的不是太规范,没有关闭资源
*/
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/hibernate3","root","123");