zoukankan      html  css  js  c++  java
  • java连接mysql数据库

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

    public class JdbcUtils {
        
        static{
            try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
        
        public static Connection getConnection() throws SQLException{
            String url = "jdbc:mysql://localhost:3306/student";
            String root = "root";
            String password = "123";
            return DriverManager.getConnection(url,root,password);
        }
        
        public static void closeConnection(Connection con,PreparedStatement ps , ResultSet rs) throws SQLException{
                
            if(con!=null && ps!=null && rs!=null){
                con.close();
                ps.close();
                rs.close();
            }
        }
    }

  • 相关阅读:
    Linux
    Linux
    Linux
    Linux
    Linux
    Python
    Linux
    Python
    MySQL
    Python
  • 原文地址:https://www.cnblogs.com/zzlback/p/8419602.html
Copyright © 2011-2022 走看看