- public static Connection getConnection(){
- //或者Class.forName("com.mysql.jdbc.Driver");
- String url ="jdbc:mysql://localhost/test?user=admin&password=&useUnicode=true&characterEncoding=utf-8";
- //myDB为数据库名
- Connection conn= null;
- try{
- Class.forName("org.gjt.mm.mysql.Driver").newInstance();
- conn = (Connection) DriverManager.getConnection(url);
- }catch(Exception e){
- e.printStackTrace();
- }
- return conn;
- }