Is it possible to connect to a datasource defined in another class, without any frameworks or servers etc just for a local application, built just for practice.
I have a class called FireBirdDataSource:
import org.firebirdsql.pool.FBWrappingDataSource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class FireBirdDataSource {
public FireBirdDataSource() {
InitialContext context = null;
FBWrappingDataSource dataSourceFB = new FBWrappingDataSource();
dataSourceFB.setDatabase("jdbc:firebirdsql:localhost/3050:C:\\DB.fdb");
dataSourceFB.setUserName("SYSDBA");
dataSourceFB.setPassword("masterkey");
try {
context = new InitialContext();
context.bind("jdbc/FBDB", dataSourceFB);
} catch (NamingException e) {
e.printStackTrace();
}
}
}
Trying to connect to it with:
InitialContext context = new InitialContext();
DataSource dataSource = (DataSource)context.lookup("jdbc/FBDB");
Connection con = dataSource.getConnection();
The Connection con = dataSource.getConnection() - can't find the getConnection() method. I seem to be doing something really wrong, but I'm not quite sure what.