Hi Viet, Thanks a lot for your prompt reply.
Let me read the article and try it. John Qi ----- Original Message ----- From: "Viet Nguyen" <[EMAIL PROTECTED]> To: <user@geronimo.apache.org> Sent: Wednesday, January 02, 2008 12:13 PM Subject: Re: question about MySql and Geronimo > On Jan 2, 2008 12:40 PM, jpmlpool <[EMAIL PROTECTED]> wrote: > > Happy New Year ! > > > > What I want to do are > > (1) when I start Geronimo, MySql server is started automatically by > > Geronimo. > > (2) I can access MySql, just like now I can access Derby. > > (3) if possible, for example, there are two Derbys and two MySqls, I can > > access them for different purpose. I do not know if this is possible, > > if > > possible, HOW TO DO. > > > > What I did are > > (1) downloaded MySql 5.0.54 and installed it. (OK) > > (2) from console I can access the MySql. (OK) > > > > mysql> show tables; > > > > +-------------------+ > > > > | Tables_in_hellodb | > > > > +-------------------+ > > > > | pet | > > > > | wishtable | > > > > +-------------------+ > > > > 2 rows in set (0.00 sec) > > > > > > > > mysql> SELECT * FROM pet; > > > > +----------+-------+---------+------+------------+------------+ > > > > | name | owner | species | sex | birth | death | > > > > +----------+-------+---------+------+------------+------------+ > > > > | Fluffy | | Harold | c | 0000-00-00 | 1993-02-04 | > > > > | Claws | | Gwen | c | 0000-00-00 | 1994-03-17 | > > > > | Buffy | | Harold | d | 0000-00-00 | 1989-05-13 | > > > > | Fang | | Benny | d | 0000-00-00 | 1990-08-27 | > > > > | Bowser | | Diane | d | 0000-00-00 | 1979-08-31 | > > > > | Chirpy | | Gwen | b | 0000-00-00 | 1998-09-11 | > > > > | Whistler | Gwen | bird | | 1997-12-09 | NULL | > > > > | Slim | | Benny | s | 0000-00-00 | 1996-04-29 | > > > > +----------+-------+---------+------+------------+------------+ > > > > 8 rows in set (0.00 sec) > > > > > > > > (3) downloaded the MySql driver mysql-connector-java-3.1.12.jar > > > > through Geronimo's console. > > > > the driver is placed in repository\mysql\mysql-connector-java\3.1.12 > > > > > > > > (4) From Eclipse I created a Java Application, and I can > > > > access the MySql using Java code below. The results are correct. > > > > > > > > Class.forName("com.mysql.jdbc.Driver").newInstance(); > > > > String url = "jdbc:mysql:///hellodb?user=abc&password=xyz"; > > Connection con = DriverManager.getConnection(url); > > > > > > > > (5) I created a Dynamic web project and a servlet, and used the > > > > same code in the servlet as above, but I got next error message. > > > > > > > > java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in classloader > > com.sn.web.db.mysql.demo.pet/SqlDemoPetStoreId/1.0/war > > at > > org.apache.geronimo.kernel.config.MultiParentClassLoader.loadOptimizedClass( > > MultiParentClassLoader.java:428) > > at > > org.apache.geronimo.kernel.config.MultiParentClassLoader.loadClass(MultiPare > > ntClassLoader.java:278) > > at java.lang.ClassLoader.loadClass(Unknown Source) > > at java.lang.ClassLoader.loadClassInternal(Unknown Source) > > at java.lang.Class.forName0(Native Method) > > at java.lang.Class.forName(Unknown Source) > > at com.sn.web.db.mysql.demo.pet.ListPets.getPets(ListPets.java:82) > > at com.sn.web.db.mysql.demo.pet.ListPets.doGet(ListPets.java:43) > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:693) > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:806) > > > I think the reason the class is not found is because you did not set a > dependency on the MySQL driver in your application. You can do this in > your geronimo-web.xml. However, it is better if you used a DataSource > to connect to the respective DBs. This way, you do not have to > hardcode the driver classname and the connection url in your > application code. For an example of how to do this, visit > http://cwiki.apache.org/GMOxDOC20/simple-database-access-sample-application.html. > > Once you write the xml descriptor that defines the datasource, you > just need to inject it into your source code through annotations or > some more xml configuration. > > Since each datasource defines a connection to a database, you can have > multiple datasources to connect to multiple different types of > databases. > > Hope this helps, > Viet > > ..... > > > > > > > > Do you have any ideas ? > > > > > > > > Thanks in advance. > > > > > > > > John Qi > > > > > > > > > > > > > > > > >