• 【mysql jdbc DbUtil()】连接、关闭数据库


    package com.java1234.jdbc.util;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    
    import com.mysql.jdbc.PreparedStatement;
    
    public class DbUtil {
        
        private static String dbUrl="jdbc:mysql://localhost:3306/db_book";    //"db_book"是数据库名字
        
        private static String dbUserName="root";    //数据库用户名
        
        private static String dbPassword="123456";   //数据库密码
        
        private static String jdbcName="com.mysql.jdbc.Driver";  //驱动
        
    //获取连接
    public Connection getCon()throws Exception{ Class.forName(jdbcName); Connection con=DriverManager.getConnection(dbUrl, dbUserName, dbPassword); return con; }
    //关闭连接
    public void close(Statement stmt,Connection con)throws Exception{ if(stmt!=null){ stmt.close(); if(con!=null){ con.close(); } } }
    //关闭连接
    public void close(PreparedStatement pstmt,Connection con)throws Exception{ if(pstmt!=null){ pstmt.close(); if(con!=null){ con.close(); } } } }
  • 相关阅读:
    第二次冲刺(二)
    第二次冲刺(一)
    5月30日学习日志
    5月29日学习日志
    5月28日学习日志
    5月27日学习日志
    5月26日学习日志
    粒子群算法-PSO
    花授粉优化算法-python/matlab
    花授粉优化算法
  • 原文地址:https://www.cnblogs.com/CPU-Easy/p/12403667.html
Copyright © 2020-2023  润新知