// Name of the Java Bean file connecting to the database dbconn. java
Package NinGoo;
Import java. SQL .*;
Public class dbconn {
Public dbconn (){
}
// Declare variable
Private Connection conn = null;
ResultSet rs = null;
Private String server = "127.0.0.1 ";
Private String port = "3306 ";
Private String db = "test ";
Private String user = "root ";
Private String pass = "password ";
Private String drivername = "com. mysql. jdbc. Driver ";
Private String URL = "jdbc: mysql: //" + server + ":" + port + "/" + db + "? User = "+ user +" & password = "+ pass;
Public Connection getConn () {// get database connection
Try {
Class. forName (drivername). newInstance ();
Conn = DriverManager. getConnection (URL );
}
Catch (Exception e ){
E. printStackTrace ();
}
Return this. conn;
}
Public ResultSet executeSQL (String str ){
Try {
Statement stmt = conn. createStatement ();
Rs = stmt.exe cuteQuery (str );
}
Catch (Exception e ){
E. printStackTrace ();
}
Return this. rs;
}
}
Source: http://ningoo.itpub.net/