I would like to return a connection to a Bean to make statements to mysql database "ccdb" I'm really not sure of
public static Connection getConnection(){
if(connection==null){
try{
Class.forName("org.gjt.mm.mysql.Driver");
connection=DriverManager.getConnection("jdbc:mysql://localhost:8084","root","ceyesuma");
}catch(Exception exc){ connection=null;}
}
return connection;
}
Here is the bean to get connected. Should this work?
package db;
import java.sql.*;
import java.sql.DriverManager;
import java.sql.Connection;
/**
*
* @author James
*/
public class DBConnection {
static String dbdriver;
static String connURL;
static String dbusername="";
static String dbpassword="";
static Connection connection=null;
/** Creates a new instance of DBConnection */
public DBConnection() {
}
public String getDbdriver(){
return dbdriver;
}
public String getConnURL(){
return connURL;
}
public String getDbusername(){
return dbusername;
}
public String getDbpassword(){
return dbpassword;
}
public void setDbdriver(String dbdriver){
DBConnection.dbdriver=dbdriver;
}
public void setConnURL(String url){
DBConnection.connURL=url;
}
public void setDbusername(String dbusername){
DBConnection.dbusername=dbusername;
}
public void setDbpassword(String dbpassword){
DBConnection.dbpassword=dbpassword;
}
public static Connection getConnection(){
if(connection==null){
try{
Class.forName("org.gjt.mm.mysql.Driver");
connection=DriverManager.getConnection("jdbc:mysql://localhost:8084","root","ceyesuma");
}catch(Exception exc){ connection=null;}
}
return connection;
}
}