jdbc

JDBCUtlis工具类

其实就是将,java连接mysql的方法进行封装,使得重复代码减少

连接和关闭都算是重复代码。

public class JDBCUtils {
public static Connection getConnect() throws IOException, ClassNotFoundException, SQLException {
//导入配置信息
Properties properties = new Properties();
properties.load(new FileInputStream("D:\\IDEA\\workspace\\mysql.properties"));
String driver = properties.getProperty("driver");
String url = properties.getProperty("url");
String user = properties.getProperty("user");
String password = properties.getProperty("password");
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, user, password);
return connection;
}
public static void closeConnect(ResultSet resultSet, Statement statement,Connection connection) throws SQLException {
if(resultSet != null){
resultSet.close();
}
if(statement != null){
statement.close();
}
if(connection != null){
connection.close();
}
}
}
url=jdbc:mysql://localhost:3306/sora?rewriteBatchedStatements=true
user=root
password=root
driver=com.mysql.cj.jdbc.Driver

事务

一个形象的例子就是,当年给人转账时,需要你的账户减少,别人账户增加。不能出现问题,只有一方增加或者减少。事务就是为了解决这样的问题。

批处理

为了提高效率,把一堆sql语句先存在一块。然后提交一堆语句,大概

本文作者:xiaoovo

本文链接:https://www.cnblogs.com/xiaoovo/p/15968084.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   xiaoovo  阅读(30)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
🔑