连接数据库的时候要用到try catch
String url = "jdbc:mysql://localhost:3306/survey?user=root&password=&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false";
protected Connection conn=null;
protected PreparedStatement pstmt;
protected ResultSet rs=null;
static{
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception e)
{
e.printStackTrace();
}
}
/**
* Connect Database
*/
public void getConn() {
String url = "jdbc:mysql://localhost:3306/survey?user=root&password=&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false";
try {
conn = DriverManager.getConnection(url);
} catch (Exception e) {
System.out.println("Database Conn Failed !");
}
}