• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

mysql connection

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have the library exercise we did in IBM WF311 class.
It is using DB2 , which is sucks.
I want to make it to run on Mysql.
I know to get a DB connection , but my problem is to keep the same code and just change the instance variable values.
Can someone tell me what is the MySQL equivalent for below DB2 variables given below. I do not have a JNDI, but
private static String initialContextFactory = "COM.ibm.db2.jndi.DB2InitialContextFactory";
private static final String FACTORY = "initialContextFactory";
private String jndiName =

How should I replace this method to suite MySQL ?
private CreateDataSource() {
jndiName = DatabaseManagement.getLookupName();
initialContextFactory = DatabaseManagement.getInitialContextFactory();
databaseName = DatabaseManagement.getDatabase();
}

Thanks a lot
Mei.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You will have to try this code out. I personally haven't used MySQL, but from friends' notes, I have gathered information for you.
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql//{localhost}/{name_of_the_database}", "{user_name}", "{password}");
Hope it helps...
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's very bad advice. Do NOT do that. This creates an unmanaged connection that WebSphere does not know about, and which is unpooled.
And exactly why do you say DB2 "sucks"?
Kyle
 
Me Fdo
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kylie
In our company we use Oracle 9i in all the WEB apps running out of intranet. Mysql is used only by developers for quick tests.
I did not mean anything bad about DB2 database but for a student like me exercise does not help once I came back to work if I can't get it to run here at work. (I have only 3 weeeks of experience in WEBSphere, Tomcat /jboss experience only by doing toy projects in the college). I have oracle 9i installed and mysql installed and want to get library project up on my machine for a week, still could not get it to work. I just showed my frustration, but nothing to do with DB2 .. I apologize if I hurt anyone withn my frustration.
Instructions in the lab exercises in WF311 is in DB2. To change the librarySETUP and libraryJava projects to run on Oracle or mysql , in the latter part of the lab instructions Authors of the SETUP project say that I can just change the databaseInformation.properties files with URL, Driver , username and password to selected any database and it should work.
They did not talk about how I will change the DB2...JNDI package(I know JNDI is used to create datasources and connections. ) and import COM.ibm.db2.jdbc.DB2DataSource package in CreateDatasource.java.
Also I don't know in oracle/mysql equivalent to following
initialContextFactory=COM.ibm.db2.jndi.DB2InitialContextFactory

--bottom line is the way they have coded the Librarysetup and libraryjava project in WF311 cannot run on Oracle /mysql just changing databaseInformation.properties file only.
I asked the Instructor he was not sure either how to make it to work on oracle/mysql.
Can you please tell me what is the Oracle and /or MySQL equivalent for below DB2 variables given below.

Can you tell me what should be the equivalent values if I were to use MySQL and Oracle (thin driver) respectively ?

----------------------
Here's the other java code I need to modify with correct oracle and mysql values..
(For Eg: I need to know the oracle equivalent of "COM.ibm.db2.jndi.DB2InitialContextFactory", "COM.ibm.db2.jdbc.app.DB2Driver" )
This is a part of properties file.
url=jdbc b2:library
driver=COM.ibm.db2.jdbc.app.DB2Driver
initialContextFactory=COM.ibm.db2.jndi.DB2InitialContextFactory
lookupName=jdbc/library
Here's a code snippet from WF311 WEBSphere class at IBM.
public class DatabaseManagement {
// resource bundle keys
private static final String USERID = "userid";
private static final String PASSWORD = "password";
private static final String DRIVER = "driver";
private static final String URL = "url";
private static final String FACTORY = "initialContextFactory";
private static final String LOOKUP = "lookupName";
private static final String DATABASE = "database";
// default values to use if no properties bundle is found
private static String userid = "USERID";
private static String password = "PASSWORD";
private static String driver = "COM.ibm.db2.jdbc.app.DB2Driver";
private static String url = "jdbc b2:library";
private static String initialContextFactory = "COM.ibm.db2.jndi.DB2InitialContextFactory";
private static String lookupName = "jdbc/library";
private static String database = "library";
private static final String file = "databaseInformation.properties";
private static PropertyResourceBundle properties;

--------------------
ublic class DatastoreFactory {
// resource bundle keys
private static final String TYPE = "type";
private static final String TYPE_EJB = "ejb";
private static final String TYPE_POOL = "pool";
private static final String TYPE_JDBC = "jdbc";
private static final String USERID = "userid";
private static final String PASSWORD = "password";
private static final String DRIVER = "driver";
private static final String URL = "url";
private static final String FACTORY = "initialContextFactory";
private static final String LOOKUPURL = "lookupURL";
private static final String LOOKUP = "lookupName";
// default values to use if no properties bundle is found
private static String type = "jdbc";
private static String userid = "USERID";
private static String password = "PASSWORD";
private static String driver = "COM.ibm.db2.jdbc.app.DB2Driver";
private static String url = "jdbc b2:library";
private static String contextFactory = "COM.ibm.db2.jndi.DB2InitialContextFactory";
private static String lookupURL="iiop:///";
private static String lookupName = "jdbc/library";
private static final String file = "databaseInformation.properties";
private static PropertyResourceBundle properties;
private static PatronDatastore patronDatastore;
private static ItemDatastore itemDatastore;
private static CopyDatastore copyDatastore;
Thanks
Mei
 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like this should work:
Connection connnect = null;
try{
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("jdbc/MyDb");
connect = ds.getConnection();
}
catch(Exception e){}
assuming that you have the pool configured correctly with WAS and the lookup is as above.
 
Me Fdo
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
In the lab exercise IBM gave us in WF311 class they said this code is re-usable.
Hence I really like to re-use the Code given by IBM in the class , want to know
How should I replace variables such as follows in mysql and in oracle...
initialContextFactory = "COM.ibm.db2.jndi.DB2InitialContextFactory";
Thanks
Mei
 
Me Fdo
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kyle Brown
I decided to use Oracle instead of mysql.
I found the oracle9i(OC4J) equivalent of initialContextFactory from their website.
com.evermind.server.ApplicationClientInitialContextFactory

Only class I am importing from oracle is classes12.zip.
How can I get the above package ?
Further digging I found another link "http://www.orionsupport.com/1053705397386.resource ". They talk about ejb. But WF311 did not have EJB projetc still uses
DATASOURCE to connect rather than via a driver manager.
Please direct me to a right path.
Thanks
Mei
 
Me Fdo
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hooray
I got the oracle equivalent for DataSource and got it the library project to work!!!
replaced the package COM.ibm.db2.jdbc.DB2DataSource; with
oracle.jdbc.pool.OracleDataSource;
It works fine
Thanks anyway!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic