• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Ranch Hand
    Posts: 77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.)
     
    author & internet detective
    Posts: 40747
    827
    Eclipse IDE VI Editor Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Ranch Hand
    Posts: 502
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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!
     
    Rancher
    Posts: 13459
    Android Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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:

     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic