dcsimg
Don't understand factory pattern for DB creation
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   kaleb_pederson
Posted On:   Monday, July 26, 2004 09:56 PM

Forgive me if you happen to have seen this message on Sun's forum, but nobody seemed to know the answer. Apparently, I'm missing something critical to get my DB Factory setup correctly. Specifically, I'm having a hard time figuring out where the host, db, user, and password options are supposed to be set. I'm currently doing something like the following: MysqlConnectionPoolDataSource ds = MysqlConnectionPoolDataSource(); ds.setServerName("myhostname"); ds.setDatabaseName("mydbname"); ds.setUser("myusername"); ds.setPassword("mypassword"); Connection conn = ds.getConnection(); ... However, I know that the prevents me from u   More>>

Forgive me if you happen to have seen this message on Sun's forum, but nobody seemed to know the answer.



Apparently, I'm missing something critical to get my DB Factory setup correctly. Specifically, I'm having a hard time figuring out where the host, db, user, and password options are supposed to be set. I'm currently doing something like the following:




			
MysqlConnectionPoolDataSource ds = MysqlConnectionPoolDataSource();
ds.setServerName("myhostname");
ds.setDatabaseName("mydbname");
ds.setUser("myusername");
ds.setPassword("mypassword");
Connection conn = ds.getConnection();
...



However, I know that the prevents me from using a different driver/db later should I need. So, I should have something more like this:




			
String dbDriver = "com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource";
DataSource ds = null;
try {
ds = Class.forName(dbDriver).newInstance();
} catch (ClassNotFoundException e) {
System.err.println("Unable to find class " + dbDriver);
return;
}
Connection conn = ds.getConnection();
...



What I don't see is where I can specify the URL that I need, which should be "jdbc:mysq://myhost/mydb?user=myusername&password=mypassword". I looked through all the class APIs that I thought were relevant, but still didn't find anything.



Could somebody enlighten me? I would also be interested in the JNDI solution and how it works, but I need to understand this first.



Thanks.

--Kaleb

   <<Less
About | Sitemap | Contact