import java.sql.*;
public class DataBase {
public Connection conn;
public Statement stmt;
public ResultSet rs=null;
public String sqlStr="";
public DataBase()
{
this.connect();
}
public boolean connect(){
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/BookStore?user=root&password=1&useUnicode=true&characterEncoding=utf-8";
conn=DriverManager.getConnection(url);
stmt = conn.createStatement ();
}catch(Exception ee){
System.out.println("connect db error:"+ee.getMessage());
return false;
}
return true;
}
public static void main(String[] args) {
try{
DataBase db = new DataBase();
db.connect();
}catch(Exception e){
e.printStackTrace();
}
}
}
阅读(3439) | 评论(0) | 转发(0) |