I am having a slight problem here. basically I want to create a connection pool to DB using a class. This pool can be usable by other classes to execute queries. I have made other classes subclasses of the connection class. here is what I have so far.
the Connection class/(connection Pool class)
import java.sql.*; public class connect extends cPool {
public static void main(String[] args) {
cPool en = new cPool(); //crate an object in the name of cPoll calss
Connection conn = null;
Object data;
data = (connect) conn;
en.readinfo(); //call object then method name
String userName = "root";
String password = "" + en.paword + "";// hold outside try catch block to get and set
String url = "" + en.url + "";
try
{
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
System.err.println("Tried connecting using" + url + userName + password +"");
}
finally
{
}
}
}
here is the Execute statement class
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class getProduct extends connect {
public static void main(String[] args) {
connect cn = new connect();
Connection conn = cn.data;
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM My_Table");
}
catch (SQLException ex) {
Logger.getLogger(getProduct.class.getName()).log(Level.SEVERE, null, ex);
}
finally
{
}
}
}
I can't execute any statements. from the 2nd class, when I do I get an error with createStatement(). It says 'Uncompilable source code - cannot find symbol' Thank You very much.