You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pyexr2f4a/连接/DBHelper.java

37 lines
1.0 KiB

5 years ago
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());
}
}