connection file

master
Vie 5 years ago
parent 8d7f18414e
commit 8ec54c3992

@ -0,0 +1,36 @@
package com.db;
import java.sql.*;
public class DBHelper {
//private String dbUrl="jdbc:mysql://localhost:3306/sushe";
private String dbUrl="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
private String dbUser="root";
private String dbPassword="123456";
//private String jdbcName="com.mysql.jdbc.Driver";
private String jdbcName="com.mysql.cj.jdbc.Driver" ;
//String driver = "com.mysql.cj.jdbc.Driver" ;
//String url = "jdbc:mysql://127.0.0.1:3306/test";
//String url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
public Connection getConn(){
Connection conn = null;
try{
Class.forName(jdbcName);
}
catch(Exception e){}
try{
conn=DriverManager.getConnection(dbUrl,dbUser,dbPassword);
}
catch(SQLException ex){}
return conn;
}
// <20><><EFBFBD><EFBFBD>
public static void main(String[] args)
{
System.out.println(new DBHelper().getConn());
}
}
Loading…
Cancel
Save