wood burning stoves 2.0*
The moose likes Servlets and the fly likes ODBC connection to MS Access works standalone, but not as servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "ODBC connection to MS Access works standalone, but not as servlet" Watch "ODBC connection to MS Access works standalone, but not as servlet" New topic
Author

ODBC connection to MS Access works standalone, but not as servlet

Wally Hartshorn
Ranch Hand

Joined: Jan 30, 2003
Posts: 77
We're starting to experiment with JDBC, and as a first test, I'm just trying to read from a Microsoft Access database. When I access the database via a normal command-line Java program, I can access it without any problems. However, when I use the exact same connection code via a servlet, I get an error.

Here is the BeerExpert class, which accesses the database:


Here's the BeerExpertTester class, which calls the BeerExpert class. It works fine from the command-line:


Here's the BeerExpertServlet class, which calls the BeerExpert class. When it does so, it gets a SQLException error:


I hadn't set up an ODBC Data Source before, so it's possible that I've somehow messed that up. However, since it works for the standalone command-line version, that seems unlikely. Just in case, though, here are the steps I took. To set up the Beer ODBC DSN, I:
  • Brought up the ODBC Data Source Administrator
  • Selected the "System DSN" tab
  • Clicked "Add"
  • Selected "Microsoft Access Driver (*.mdb)"
  • Clicked "Finish"
  • Entered "Beer" as the Data Source Name
  • Clicked "Selected"
  • Browsed to the database, selected it, and clicked "OK"


  • The error that I'm getting is "java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.", with an ErrorCode of "-1023" and a SQLState of "S1009".

    All of this is on Windows XP Pro. Any suggestions?


    Wally Hartshorn
    Wally Hartshorn
    Ranch Hand

    Joined: Jan 30, 2003
    Posts: 77
    I've figured out a partial solution to the problem. For some reason, when the *.mdb file is located on the C: drive, we can access it fine. However, when it is located on the G: drive (which is actually just a mapped network drive located on a Novell Netware server), then it doesn't work for the servlet (although it works for the command-line version in both cases). Odd.

    Any ideas as to why that would be the case? (Yes, I have write access to the file on the network drive.)
    Jeanne Boyarsky
    internet detective
    Marshal

    Joined: May 26, 2003
    Posts: 30382
        
    150

    Wally,
    Welcome to JavaRanch!

    Servlets may have security permissions and not be allowed to access the network drive. I'm moving this to the servlet forum for you so this can be discussed in more detail.


    [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
    Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
    Jayesh Lalwani
    Ranch Hand

    Joined: Nov 05, 2004
    Posts: 502
    Is your Web Server running as standalone or Windows service?
    In Windows, the drive mapping is specific to user, and by default Windows Services run as a "Local System" user. Maybe your G: is not valid for the Web Server
    Wally Hartshorn
    Ranch Hand

    Joined: Jan 30, 2003
    Posts: 77
    Originally posted by Jayesh Lalwani:
    Is your Web Server running as standalone or Windows service?


    That makes sense. I checked and Tomcat is running as a Windows service, which means that it is running as a different user that doesn't "see" the G: drive. I'll have to investigate how to either run Tomcat as the logged in user or how to allow the Windows service to see the G: drive.

    Thanks!
    David O'Meara
    Rancher

    Joined: Mar 06, 2001
    Posts: 13459

    Sorry, I thought of that too. You may be able to keep it as-is but refer to the file using a DNSless connection and the machine name rather than the mapped drive such as:

     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: ODBC connection to MS Access works standalone, but not as servlet