Class.forName("org.g[color=red]j[/color]t.mm.mysql.Driver").newInstance();
[code]import java.sql.*;
public class MysqlJdbc {
private String url = "jdbc:mysql://localhost:3306/lunchclub";
private Connection conn = null;
private ResultSet rs = null;
private Statement stmt = null;
private PreparedStatement pstmt = null;
public MysqlJdbc{
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection(url,"root","abc123");
}catch(Exception eb){
eb.printStackTrace();
}
}
public ResultSet getRs(String sql){
try{
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}catch(Exception eb){
eb.printStackTrace();
}
return rs;
}
public PreparedStatement getPstmt(String sql){
try{
pstmt = conn.prepareStatement(sql);
}catch(Exception ec){
ec.printStackTrace();
}
return pstmt;
}
public void closeRs(){
try{
rs.close();
stmt.close();
conn.close();
}catch(Exception ed){
ed.printStackTrace();
}
}
public void closePstmt(){
try{
pstmt.close();
conn.close();
}catch(Exception ef){
ef.printStackTrace();
}
}
}[/code]
[code]import java.sql.*;
public class MysqlJdbc {
private String url = "jdbc:mysql://localhost:3306/lunchclub";
private Connection conn = null;
private ResultSet rs = null;
private Statement stmt = null;
private PreparedStatement pstmt = null;
public MysqlJdbc{
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection(url,"root","abc123");
}catch(Exception eb){
eb.printStackTrace();
}
}
public ResultSet getRs(String sql){
try{
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}catch(Exception eb){
eb.printStackTrace();
}
return rs;
}
public PreparedStatement getPstmt(String sql){
try{
pstmt = conn.prepareStatement(sql);
}catch(Exception ec){
ec.printStackTrace();
}
return pstmt;
}
public void closeRs(){
try{
rs.close();
stmt.close();
conn.close();
}catch(Exception ed){
ed.printStackTrace();
}
}
public void closePstmt(){
try{
pstmt.close();
conn.close();
}catch(Exception ef){
ef.printStackTrace();
}
}
}[/code]