aspose file tools*
The moose likes JDBC 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
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: 29220
        
    135

    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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: ODBC connection to MS Access works standalone, but not as servlet
     
    Similar Threads
    Compiling servlet version two code in HFSJ
    Compilation Problem in CHAP3 example
    ODBC connection to MS Access works standalone, but not as servlet
    error with mvc application
    Compile error.