I have the following code :
public class My_program {
class dbConnect {
public dbConnect();
public void connect_to_db(String connect_string) {
Class.forName(...);
...
}
}
public static void main(String[] args) {
String connect_string = "jdbc...";
dbConnect db = new dbConnect();
db.connect_to_db(connect_string)
}
}
When I try to compile it, the following error occurs :
error: non-static variable this cannot be referenced from a static context
so I tried to make the dbConnect
static like this : static class dbConnect
and it's working ok but java is generating an extra .class
file : My_program$dbConnect.class
that I do not want.
So how can I have a single .class
file and get the code to work .