CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009
    Posts
    5

    unable to connect to a mySQL database

    I have developed a small JSP application that uses a mySQL database, a single JSP page (which simply displays the contents of a table in my db), and a servlet, which contains the entity manager and sql statements. I link to the database using the xml file (rather than in the code), which contains this:

    Code:
    ...
    <properties>
           <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/baseball8"/> 
           <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/> 
           <property name="openjpa.ConnectionUserName" value="root"/> 
           <property name="openjpa.ConnectionPassword" value="password"/> 
           <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/> 
        </properties>
    ...
    When I access the servlet from a web browser, I get the following error (which is actually quite detailed; last line is the error):

    <openjpa-1.2.1-r752877:753278 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-1.2.1-r752877:753278 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "com.mysql.jdbc.Driver" and URL "jdbc:mysql://localhost:3306/baseball8". You may have specified an invalid URL.
    It says my URL is invalid. I KNOW this is the right URL as I have seen it countless places on the net. If I browse to that url in my web browser, I get an octet stream. If I use the command line interface for mysql, it works. If I connect to the sql database using Eclipse, it works. I can connect just fine. I do have the mysql connector in my class path, as well as the opengpl Apache libraries.

    I am completely stumped as to the cause of the bug! Any help (or even guesses!) would be greatly appreciated.

    Thanks,

    Niel

  2. #2
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: unable to connect to a mySQL database

    - Do you have the driver set for the server?
    - Try the url without the port: //localhost/baseball8
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

  3. #3
    Join Date
    May 2009
    Posts
    5

    Re: unable to connect to a mySQL database

    Wow after several days of debugging, I finally figured it out. The associated *.jar files for the mySQL connector and taglibs have to be copied to the Apache server's "lib" directory, despite them being in the class path for the Eclipse project and also exported from there.

    Niel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured