java - Access JDBC methods from another class within the same package -
i have database
class imports java.sql.*
, have following variables
connection connect; preparedstatement statement; resultset result; public database() {} //constructor connect db [successful connection]
now create instance in class database db = new database();
, , have this:
statement = connect.statement("sql query");
but in class, have this:
db.statement = db.connect.db.statement("sql query");
it showing error looks weird.
i think possible solution create local variables in class
connection connect = db.connect; preparedstatement statement = db.statement;
which makes database
useless class.
there misunderstanding in approach
statement = connect.statement("sql query"); <--wrong statement statement = connect.preparestatement("sql query"); <--correct statement
so in class should
db.statement = db.connect.preparestatement("sql query"); <--worked
Comments
Post a Comment