sevents

package com.neu.util;

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

/**
*
*数据库连接工具类
*请不要修改代码
*
*/
public class DBUtil {
/**
*
* 获得数据库连接对象
* @return 数据库连接对象
*/
public static Connection getConnection() {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/xwebdb";
String user = "xwebdb";
String password = "xwebdb";
Connection con=null;
try {
Class.forName(driver);
con = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
e.printStackTrace();
}

return con;
}

/**
* 关闭数据库连接对象
* @param conn 数据库连接对象
*/
public static void closeConnection(Connection conn) {
try {
conn.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}

public static void main(String[] args) {
Connection conn=getConnection();
System.out.println(conn);
closeConnection(conn);
}
}

分类:

技术点:

相关文章:

  • 2022-01-07
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2022-01-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-12-17
  • 2021-12-26
  • 2022-12-23
  • 2022-01-07
相关资源
相似解决方案