1 package com.dao.db;
 2 
 3 import java.sql.Connection;
 4 import java.sql.SQLException;
 5 
 6 /**
 7  * 数据库连接层MYSQL
 8  * @author Administrator
 9  *
10  */
11 public class DBConnection {
12     
13     
14     /**
15      * 连接数据库
16      * @return
17      */
18     public static Connection getDBConnection()
19     {
20         // 1. 注册驱动
21         try {
22             Class.forName("com.mysql.jdbc.Driver");
23         } catch (ClassNotFoundException e) {
24             // TODO Auto-generated catch block
25             e.printStackTrace();
26         }
27         // 获取数据库的连接
28         try {
29             Connection conn  = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/mysql?useUnicode=true&characterEncoding=utf-8", "root", "root");
30             return conn;
31         } catch (SQLException e1) {
32             e1.printStackTrace();
33         }
34         return null;
35     }
36     
37 }
连接数据库

相关文章:

  • 2022-12-23
  • 2021-12-31
  • 2021-07-10
  • 2021-05-29
  • 2021-09-15
  • 2022-01-21
  • 2021-08-09
猜你喜欢
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2021-11-29
  • 2022-12-23
  • 2021-07-01
相关资源
相似解决方案