zoukankan      html  css  js  c++  java
  • 数据库驱动相关代码

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

    public class DBUtil {
    public static Connection getConnection() {
    try {

    Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    String user = "数据库用户名";
    String password = "数据库密码";
    String url = "jdbc:mysql://localhost:3306/数据库名";
    Connection connection = null;
    try {

    connection = DriverManager.getConnection(url,user,password);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return connection;
    }


    public static void close(Connection connection ) {
    try {
    if (connection != null) {
    connection.close();
    }

    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    public static void close(PreparedStatement preparedStatement ) {
    try {
    if (preparedStatement != null) {
    preparedStatement.close();
    }

    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    public static void close(ResultSet resultSet ) {
    try {
    if (resultSet != null) {
    resultSet.close();
    }

    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    }

  • 相关阅读:
    iOS开发实用技术之MapKit框架的使用
    iOS开发实用技术之CoreLocation框架
    iOS开发UI之KVC(取值/赋值)
    iOS开发UI之自定义View
    iOS开发UI之UIButton的基本使用
    iOS开发UI之UIImageView的基本使用
    iOS开发UI之 UILabel的基本使用
    iOS开发UI之UILabel的基本使用
    tensorflow 梯度下降以及summary
    leetcode_38
  • 原文地址:https://www.cnblogs.com/lx06/p/14164557.html
Copyright © 2011-2022 走看看