Note: Not a java EE question
In java, I need to pass an SQL Connection from one class to another as a parameter. But it seems that the receiving class gets the Connection object but it is null and not connected.
I read java EE uses a pool. But my project is small with a localhost connection using the Driver manager of JDBC. Also I read java does no pass by reference.
Any way I can pass a live connection from one class to another?
EDIT: IN CLASS CONNECT
try
{
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection(
"jdbc:mysql://localhost/MYDATABASE?user="+username+"&password="+password);
return connect;
}catch(Exception e){
return null;
IN MY MAIN CLASS
connect c = new connect(user,pass);
catch(Exception e){ return null; }is what's happening. Adde.printStackTrace();and see for yourself.