JDBC学习笔记

JDBCTest01.java:

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBCTest01 {
	public static void main(String[] args){
		Connection conn = null;
		Statement stmt = null;
	try{
		//1、注册驱动
		Driver driver = new com.mysql.jdbc.Driver();//多态 。父类型引用指向了子类型对象
		DriverManager.registerDriver(driver);
		//2、获取连接
		/*
		 * url:统一资源定位符(网络中某个资源的绝对路径)
		 * https://www.baidu.com/ 这就是url。
		 * url包括哪几部分?
		 * 协议
		 * IP
		 * PORT
		 * 资源名
		 * 
		 * http://182.61.200.7:80/index.html
		 * http:// 通信协议
		 * 182.61.200.7 服务器IP地址
		 * 80 服务器上软件的端口
		 * index.html 是服务器上某个资源名
		 * 
		 * jdbc:mysql://127.0.0.1:3306/ccnode
		 * jdbc:mysql://协议
		 * 127.0.0.1 IP地址
		 * 3306 mysql数据库端口号
		 * ccnode 具体的数据库实例名
		 * 
		 * 说明:localhost和127.0.0.1都是本机IP地址
		 */
		String url = "jdbc:mysql://127.0.0.1:3306/ccnode?serverTimezone=UTC&characterEncoding=utf-8";
		String user = "root";
		String password = "7erc1999";
	    conn = DriverManager.getConnection(url,user,password);
		//com.mysql.cj.jdbc.ConnectionImpl@1b9e1916
		
		System.out.println("数据库连接对象:"+conn);
		
		//3、获取数据库操作对象(statement专门执行sql语句的)
	    stmt = conn.createStatement();
		
		//4、执行sql
		String sql = "insert into dept(deptno,dname,loc)values(60,'personnel','BeiJing')";
		//专门执行DML语句的(insert delete update)
		//返回值是"影响数据库中的记录条数"
		int count = stmt.executeUpdate(sql);
		System.out.println(count==1?"保存成功":"保存失败");
		
		//5、处理查询结果集
	}catch(SQLException e){
			e.printStackTrace();
		}finally{
			//6、释放资源
			//为了保证资源一定释放,在finally语句块中关闭资源
			//并且遵循从小到大依次关闭
			//分别对其try..catch..
			try{
				if(stmt != null){
					stmt.close();
				}
			}catch(SQLException e){
				e.printStackTrace();
			}
			try{
				if(conn != null){
					conn.close();
				}
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
	}
		
	}


JDBCTest02.java:

/*
 * JDBC完成delete
 */
package JDBC;
import java.sql.*;
public class JDBCTest02 {
	public static void main(String[] args){
		Connection conn = null;
		Statement stmt = null;
		try{
			//1、注册驱动
			DriverManager.registerDriver(new com.mysql.jdbc.Driver());
			//2、获取连接
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ccnode?serverTimezone=UTC&characterEncoding=utf-8","root","7erc1999");
			//3、获取数据库操作对象
			stmt = conn.createStatement();
			//执行语句
			String sql = "delete from dept where deptno = 60";
			//JDBC中的语句不需要提供分号结尾
			//String sql = "update dept set dname = '销售部',loc = '天津'where deptno = 40";
			int count = stmt.executeUpdate(sql);
			System.out.println(count==1?"删除成功":"删除失败");
			
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			//释放资源
			if(stmt!=null){
				try{
					stmt.close();
					}catch(SQLException e){
						e.printStackTrace();
					}
			}
			if(conn!=null){
				try{
					conn.close();
					}catch(SQLException e){
						e.printStackTrace();
					}
			}
		}
	}

}

JDBCTest03.java:

/*
 * 注册驱动的另一种方式(这种方式常用)
 */
package JDBC;
import java.sql.*;
public class JDBCTest03 {
	public static void main(String[] args){
		try{
			//1、注册驱动
			//这是注册驱动的第一种写法
			//DriverManager.registerDriver(new com.mysql.jdbc.Driver());
			//注册驱动的第二种写法:常用的
			//为什么这种方法常用?因为参数是一个字符串,字符串可以写到xxxx.properties文件中。
			//以下方法不需要接收返回值,因为我们只想接收它的类加载动作。
			Class.forName("com.mysql.jdbc.Driver");
			//2、获取连接
			Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ccnode?serverTimezone=UTC&characterEncoding=utf-8","root","7erc1999");
			//com.mysql.cj.jdbc.ConnectionImpl@1b9e1916
			System.out.println(conn);
		}catch(SQLException e){
			e.printStackTrace();
		}catch(ClassNotFoundException e){
			e.printStackTrace();
		}
	}

}

JDBCTest04.java:

//将连接数据库的所有信息配置到配置文件中
/*
 * 实际开发中不建议把链接数据库的信息写死到java程序中
 */
package JDBC;
import java.util.*;
import java.io.FileInputStream;
import java.sql.*;
public class JDBCTest04 {
	public static void main(String[] args)throws Exception{
		
		//使用资源绑定器绑定属性配置文件
		FileInputStream fis = null;
		String filePath = "C:/Users/z/workspace/Practice/src/JDBC/jdbc.properties";
		
			fis = new FileInputStream(filePath);
		
		
		Properties p = new Properties();
		
			p.load(fis);
		
		String driver= p.getProperty("driver");
		String url = p.getProperty("url");
		String user = p.getProperty("user");
		String password = p.getProperty("password");
		
		
		//ResourceBundle bundle = ResourceBundle.getBundle("jdbc");
		//String driver = fis.getString("driver");
		//String url = fis.getString("url");
		//String user = fis.getString("user");
		//String password = fis.getString("password");
		
		Connection conn = null;
		Statement stmt = null;
		try{
			//1、注册驱动
			Class.forName(driver);
			//2、获取连接
			conn = DriverManager.getConnection(url,user,password);
			//3、获取数据库操作对象
			stmt = conn.createStatement();
			//执行sql语句
			String sql = "update dept set dname = '销售部',loc='天津'where deptno = 60";
			int count = stmt.executeUpdate(sql);
			System.out.println(count==1?"修改成功":"修改失败");
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			//6、释放资源
			if(stmt!=null){
				try{
					stmt.close();
					}catch(SQLException e){
						e.printStackTrace();
					}
			}
			if(conn!=null){
				try{
					conn.close();
					}catch(SQLException e){
						e.printStackTrace();
					}
			}
		}
	}

}

JDBCTest05.java:

/*
 * 处理查询结果集
 */
package JDBC;
import java.sql.*;
import java.util.*;
public class JDBCTest05 {
	public static void main(String[] args){
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try{
			//1、注册驱动
			Class.forName("com.mysql.jdbc.Driver");
			
			//2、获取连接
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ccnode?serverTimezone=UTC&characterEncoding=utf-8","root","7erc1999");
			
			//3、获取数据库操作对象
			stmt = conn.createStatement();
			
			//4、执行sql语句
			String sql = "select * from t_user";
			//int executeUpdate(insert/delete/update)
			//ResultSet executeQuery(select)
			rs = stmt.executeQuery(sql);//专门执行DQL语句的方法
			//5、处理查询结果集
			//boolean flag1 = rs.next();
			//System.out.println(flag1);//true
			while(rs.next()){
				String realName = rs.getString("realName");
				String loginName = rs.getString("loginName");
				String loginPwd = rs.getString("loginPwd");
				System.out.println(realName+","+loginName+","+loginPwd);
			}
		}catch(Exception e){
			e.printStackTrace();
			}finally{
				//6、释放资源
				if(rs!=null){
					try{rs.close();
					}catch(Exception e){
						e.printStackTrace();
						}
				if(stmt!=null){
					try{stmt.close();
				    }catch(Exception e){
						e.printStackTrace();
						}
				if(conn!=null){
					try{conn.close();
				    }catch(Exception e){
						e.printStackTrace();
						}
				}
			}
	  }
	}
  }
}

JDBCTest06.java:

package JDBC;

import java.sql.*;
import java.util.*;

/*
 * 实现功能:
 * 1、需求:
 *       模拟用户登录功能的实现
 * 2、业务描述:
 *       程序运行时,提供一个登录的入口,可以让用户输入用户名和密码
 *       用户输入用户名和密码之后,提交信息
 *       Java程序收集到用户信息
 *       连接数据库验证用户名和密码是否合法
 * 3、数据的准备
 *       在实际开发中,表的设计会使用专业的建模工具,我们这里安装一个建模工具:powerDesigner
 *       使用PD工具来进行数据库的设计(参见user-login.sql脚本)
 */
public class JDBCTest06 {
	public static void main(String[] args){
		//初始化一个界面
		Map<String,String> userLoginInfo = initUI();
		//验证用户名,密码
		boolean loginSuccess = login(userLoginInfo);
		//最后输出结果
		System.out.println(loginSuccess?"登录成功":"登录失败");
	}
	/*
	 * 用户登录
	 * @param userLoginInfo 用户登录信息
	 * @return false表示失败 true表示成功
	 */

	private static boolean login(Map<String, String> userLoginInfo) {
		//打标记的意识
		boolean loginSuccess = false;
		
		// TODO 自动生成的方法存根
		//JDBC代码
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		
		
		//单独定义变量
		String loginName = userLoginInfo.get("loginName");
		String loginPwd = userLoginInfo.get("loginPwd");
	
		//1、注册驱动
		try {
			//1、注册驱动
			Class.forName("com.mysql.jdbc.Driver");
			//2、获取连接
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ccnode","root","7erc1999");
			//3、获取数据库操作对象
			stmt = conn.createStatement();
			//4、执行sql语句
			String sql = "select * from t_user where loginName = '"+loginName+"' and loginPwd = '"+loginPwd+"'";
			rs = stmt.executeQuery(sql);
			//5、处理查询结果集
			if(rs.next()){
				//登录成功
				loginSuccess = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			//6、释放资源
			if(rs!=null){
				try{rs.close();}catch(Exception e){e.printStackTrace();}
			}
			if(stmt!=null){
				try{stmt.close();}catch(Exception e){e.printStackTrace();}
			}
			if(conn!=null){
				try{conn.close();}catch(Exception e){e.printStackTrace();}
			}


		}
		
	
		return loginSuccess;
	}
	/*
	 * 初始化用户界面
	 * @return  用户输入的用户名和密码等登录信息
	 */

	private static Map<String, String> initUI() {
		// TODO 自动生成的方法存根
		Scanner s = new Scanner(System.in);
		System.out.print("用户名:");
		String loginName = s.nextLine();
		
		System.out.print("密码:");
		String loginPwd = s.nextLine();
		
		Map<String,String> userLoginInfo = new HashMap<>();
		userLoginInfo.put("loginName", loginName);
		userLoginInfo.put("loginPwd", loginPwd);
		return userLoginInfo;
	}

}

JDBCTest07.java:

package JDBC;
import java.sql.*;
import java.util.*;

public class JDBCTest07 {
		public static void main(String[] args){
			//初始化一个界面
			Map<String,String> userLoginInfo = initUI();
			//验证用户名,密码
			boolean loginSuccess = login(userLoginInfo);
			//最后输出结果
			System.out.println(loginSuccess?"登录成功":"登录失败");
		}
		/*
		 * 用户登录
		 * @param userLoginInfo 用户登录信息
		 * @return false表示失败 true表示成功
		 */

		private static boolean login(Map<String, String> userLoginInfo) {
			//打标记的意识
			boolean loginSuccess = false;
			
			// TODO 自动生成的方法存根
			//JDBC代码
			Connection conn = null;
			PreparedStatement ps = null;
			ResultSet rs = null;
			
			
			//单独定义变量
			String loginName = userLoginInfo.get("loginName");
			String loginPwd = userLoginInfo.get("loginPwd");
		
			//1、注册驱动
			try {
				//1、注册驱动
				Class.forName("com.mysql.jdbc.Driver");
				//2、获取连接
				conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ccnode","root","7erc1999");
				//3、获取数据库操作对象
				//sql语句的框子 其中一个?表示一个占位符 一个占位符接收一个值  注意占位符不能用引号括起来
				String sql = "select * from t_user where loginName = ? and loginPwd = ?";
				//程序执行到此处,会发送sql语句框子给DBMS,然后DBMS进行sql语句的预先编译
				ps = conn.prepareStatement(sql);
				//给占位符?传值 (第一个问号下标是1,第二个问号下标是2,JDBC中所有下标从1开始)
				ps.setString(1,loginName);
				ps.setString(2,loginPwd);
				
				
				//4、执行sql语句
				
				rs = ps.executeQuery();
				//5、处理查询结果集
				if(rs.next()){
					//登录成功
					loginSuccess = true;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}finally{
				//6、释放资源
				if(rs!=null){
					try{rs.close();}catch(Exception e){e.printStackTrace();}
				}
				if(ps!=null){
					try{ps.close();}catch(Exception e){e.printStackTrace();}
				}
				if(conn!=null){
					try{conn.close();}catch(Exception e){e.printStackTrace();}
				}


			}
			
		
			return loginSuccess;
		}
		/*
		 * 初始化用户界面
		 * @return  用户输入的用户名和密码等登录信息
		 */

		private static Map<String, String> initUI() {
			// TODO 自动生成的方法存根
			Scanner s = new Scanner(System.in);
			System.out.print("用户名:");
			String loginName = s.nextLine();
			
			System.out.print("密码:");
			String loginPwd = s.nextLine();
			
			Map<String,String> userLoginInfo = new HashMap<>();
			userLoginInfo.put("loginName", loginName);
			userLoginInfo.put("loginPwd", loginPwd);
			return userLoginInfo;
		}


}

JDBCTest08.java:

package JDBC;
import java.util.*;
import java.sql.*;
public class JDBCTest08 {
	public static void main(String[] args){
	
		Scanner s = new Scanner(System.in);
		System.out.println("请输入desc或asc,desc表示降序,asc表示升序");
		System.out.print("请输入:");
		String keywords = s.nextLine();
		
		//执行SQL
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ccnode","root","7erc1999");
			stmt = conn.createStatement();
			
			String sql = "select ename from emp order by ename "+keywords;
			rs = stmt.executeQuery(sql);
			
			
			while(rs.next()){
				System.out.println(rs.getString("ename"));
			}
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}finally{
			if(rs!=null){
				try{rs.close();}catch(Exception e){e.printStackTrace();}
			}
			if(stmt!=null){
				try{stmt.close();}catch(Exception e){e.printStackTrace();}
			}
			if(conn!=null){
				try{conn.close();}catch(Exception e){e.printStackTrace();}
			}
		}
		
	}

}
/*      Scanner s = new Scanner(System.in);
		System.out.println("请输入desc或asc,desc表示降序,asc表示升序");
		System.out.print("请输入:");
		String keywords = s.nextLine();
		
		//执行SQL
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ccnode","root","7erc1999");
			
			String sql = "select ename from emp order by ename ?";
			ps = conn.prepareStatement(sql);
			ps.setString(1,keywords);
			
			rs = ps.executeQuery(sql);
			
			while(rs.next()){
				System.out.println(rs.getString("ename"));
			}
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}finally{
			if(rs!=null){
				try{rs.close();}catch(Exception e){e.printStackTrace();}
			}
			if(ps!=null){
				try{ps.close();}catch(Exception e){e.printStackTrace();}
			}
			if(conn!=null){
				try{conn.close();}catch(Exception e){e.printStackTrace();}
			}
		}
		
*/

JDBCTest09.java:

package JDBC;

import java.sql.*;

/*
 * 使用PreparedStatement完成insert delete update
 */
public class JDBCTest09 {
	public static void main(String[] args){
		Connection conn = null;
		PreparedStatement ps = null;
	
		
		
		try {
		//注册驱动
			Class.forName("com.mysql.jdbc.Driver");
		//获取连接
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ccnode","root","7erc1999");
		//获取预编译的数据库操作对象
			//增
		    String sql = "insert into dept(deptno,dname,loc)values(?,?,?)";
			ps = conn.prepareStatement(sql);
			ps.setInt(1,70);
			ps.setString(2,"人事部");
			ps.setString(3,"上海");
			
			/*删
			String sql = "delete from dept where deptno = ?";
			ps = conn.prepareStatement(sql);
			ps.setInt(1,70);
			*/
			/*改
			String sql = "update dept set dname = ?,loc = ?where deptno = ?";
			ps = conn.prepareStatement(sql);
			ps.setString(1,"研发一部");
			ps.setString(2,"深圳");
			ps.setInt(3,70);
			*/
		//执行sql语句
			int count = ps.executeUpdate();
			System.out.println(count);
			} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}finally{
		//释放资源
			if(ps!=null){
				try{ps.close();}catch(Exception e){e.printStackTrace();}
			}
			if(conn!=null){
				try{conn.close();}catch(Exception e){e.printStackTrace();}
			}
		}
		
	}

}

JDBCTest10.java:

package JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class JDBCTest10 {
	public static void main(String[] args){
		Connection conn = null;
		PreparedStatement ps = null;
	
		
		
		try {
		//注册驱动
			Class.forName("com.mysql.jdbc.Driver");
		//获取连接
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ccnode","root","7erc1999");
		//获取预编译的数据库操作对象
			String sql = "update dept set dname = ? where deptno = ?";
			ps = conn.prepareStatement(sql);
			ps.setString(1,"X部门");
			ps.setInt(2,60);
		//执行sql语句
			int count = ps.executeUpdate();//第一次执行update语句
			//重新给占位符传值
			ps.setString(1,"Y部门");
			ps.setInt(2,20);
			count = ps.executeUpdate();//第二次执行update语句
			System.out.println(count);
			
			} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}finally{
		//释放资源
			if(ps!=null){
				try{ps.close();}catch(Exception e){e.printStackTrace();}
			}
			if(conn!=null){
				try{conn.close();}catch(Exception e){e.printStackTrace();}
			}
		}
		
	}

}

JDBCTest11.java:

package JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/*
 * sql脚本
 * drop table if exists t_act;
 * create table t_act(
 * actno int,
 * balance double(7,2)//注意7表示有效数字的个数,2表示小数位的个数。
 * );           
 * insert into t,balance)values(111,20000);
 * insert into t,balance)values(222,0);
 * commit;      
 * select * from
 * 重点三行代码:
 * conn.setAutoCommit(false);
 * conn.commit();
 * conn.rollback();
 */

public class JDBCTest11 {
	public static void main(String[] args){
		Connection conn = null;
		PreparedStatement ps = null;
	
		
		
		try {
		//注册驱动
			Class.forName("com.mysql.jdbc.Driver");
		//获取连接
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ccnode","root","7erc1999");
		//将自动提交修改为手动提交
			conn.setAutoCommit(false);//开启事务
		//获取预编译的数据库操作对象
			String sql = "update t_act set balance = ? where actno = ?";
			ps = conn.prepareStatement(sql);
			
			
		//给?传值
			ps.setDouble(1,10000);
			ps.setDouble(2,111);
			int count = ps.executeUpdate();
			
			//String s = null;
			//s.toString();
			
		//给?传值
			ps.setDouble(1,10000);
			ps.setDouble(2,222);
		    count += ps.executeUpdate();
		    
		    System.out.println(count==2?"转账成功":"转账失败");
		//程序能够走到这里说明以上程序没有异常,事务结束,手动提交数据。
		    conn.commit();//提交事务
			} catch (Exception e) {
				if(conn!=null){
					try {
						conn.rollback();//回滚事务
					} catch (SQLException e1) {
						// TODO 自动生成的 catch 块
						e1.printStackTrace();
					}
				}
				
			// TODO 自动生成的 catch 块
			e.printStackTrace();
			
		}finally{
		//释放资源
			if(ps!=null){
				try{ps.close();}catch(Exception e){e.printStackTrace();}
			}
			if(conn!=null){
				try{conn.close();}catch(Exception e){e.printStackTrace();}
			}
		}
		
	}


}

JDBCTest12.java:

package JDBC;
/*
 * 这个程序两个任务:
 * 第一:测试Util是否好用
 * 第二:模糊查询怎么写
 */
import java.sql.*;
import Utils.DBUtil;
public class JDBCTest12 {
	public static void main(String[] args){
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			//获取连接
			conn = DBUtil.getConnection();
			//获取预编译的数据库操作对象
			String sql = "select ename from emp where ename like ?";
			ps = conn.prepareStatement(sql);
			ps.setString(1,"_A%");
			rs = ps.executeQuery();
			while(rs.next()){
				System.out.println(rs.getString("ename"));
			}
			//错误的写法
			/*String sql = "select ename from emp where ename like '_?%'";
			ps = conn.prepareStatement(sql);
			ps.setString(1,"A");
			*/
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}finally{
			//释放资源
			DBUtil.close(conn, ps, rs);
		}
		
		
	}

}

JDBCTest13.java:

package JDBC;
/*
 * 这个程序开启一个事务
 * 这个事务专门查询
 * 并且使用悲观锁/行级锁
 * 锁住相关的记录
 */
import java.sql.*;
import Utils.DBUtil;
public class JDBCTest13 {
	public static void main(String[] args){
		
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		try {
			conn = DBUtil.getConnection();//开启事务
			conn.setAutoCommit(false);//提交事务(事务结束)
			
			String sql = "select ename,job,sal from emp where job = ? for update";
			ps = conn.prepareStatement(sql);
			ps.setString(1,"MANAGER");
			
			rs = ps.executeQuery();
			while(rs.next()){
				System.out.println(rs.getString("ename")+","+rs.getString("job")+","+rs.getDouble("sal"));
			}
			conn.commit();
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			if(conn!=null){
				//回滚事务(事务结束)
				try {
					conn.rollback();
				} catch (SQLException e1) {
					// TODO 自动生成的 catch 块
					e1.printStackTrace();
				}
			}
			e.printStackTrace();
		}finally{
			DBUtil.close(conn, ps, rs);
			
		}
		
	}
	
	

}

JDBCTest14.java:

package JDBC;
/*
 * 这个程序负责修改被锁定的记录
 */
import java.sql.*;
import Utils.DBUtil;
public class JDBCTest14 {
	public static void main(String[] args){
		
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			conn = DBUtil.getConnection();
			conn.setAutoCommit(false);
			
			String sql = "update emp set sal = sal*1.1 where job = ?";
			ps = conn.prepareStatement(sql);
			ps.setString(1,"MANAGER");
			int count = ps.executeUpdate();
			System.out.println(count);
			
			conn.commit();
			
		} catch (Exception e) {
			if(conn!=null){
				try {
					conn.rollback();
				} catch (SQLException e1) {
					// TODO 自动生成的 catch 块
					e1.printStackTrace();
				}
			}
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}finally{
			DBUtil.close(conn, ps, null);
		}
		
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值