Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file

 
m pa
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Background:
I am developing in Eclipse and using Struts 2 framework to build and deploy .war file to JBoss.

There is an action class that I am using to insert a user into a database table - pretty simple stuff

I get the following exception for executeUpdate() method.

DEBUG com.opensymphony.xwork2.DefaultActionInvocation.debug:68 - Executing action method = execute
[STDOUT] >>>>>>>>>>insert into catNav.USERS values('mm', 'pp', 88, 'mm.pp@yahoo.com');
[STDOUT] java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file 'C:\java\jboss-4.2.3.GA\bin\catNav.mdb'.

The puzzling thing is that the file referred to is different to the one I had set it to with the following:



The method to get connection does not throw exception, below is the code:



Now I have standalone Java program, with the above code, that when compiled and executed in CMD, then the data is successfully inserted into the database (I use Microsoft Access to verify).
... but not when the Java code is running in JBoss.


I guess one workaround would be to create the database (.mdb) in the folder listed by the exception but surely there has to be a way to fix the problem??
 
Balaji Vankadaru
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for establishing connection with the database you need few things to setup firstly ...!

you need the register the driver. (Have the driver jar in your class path)

you need to pass the db URL along with the user name and password

then you need to establish connection and prepare statement following by executing Query.




 
m pa
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for repsonse.

Balaji Vankadaru wrote:for establishing connection with the database you need few things to setup firstly ...!
you need the register the driver. (Have the driver jar in your class path)



aplogies - I had missed out a previous line, but I thought it was a given otherwise I would have gotten exception earlier and not reach the code above.



apparently the above class is in rt.jar - I do not have that in my classpath but is must be duplicated in another jar since I do not get exception. (if I change the name, say append 'A' then get exception, as expected).

Balaji Vankadaru wrote:
you need to pass the db URL along with the user name and password


ok, I am going to need help with this one - I have no db users defined, and am not sure what URL I should use.

Balaji Vankadaru wrote:
then you need to establish connection and prepare statement following by executing Query.


I am reasonably sure the connection is established and the statment is correct - the fact that is runs successfully in the standalone Java program proves that..... except not when deployed in JBoss.

I am trawling the web to get more info. and it may have something to do with JNDI and referring to my datasource in web.xml ???
 
Balaji Vankadaru
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.tutorialspoint.com/jdbc/jdbc-select-records.htm


http://www.tutorialspoint.com/servlets/servlets-database-access.htm


jndi is useful in a situation where you have a data source defined at a separate place and you are creating a client to get an access to the data source. then jndi would be handy. when you have a session bean and deploy it in jboss it would create a jndi resource and you can get an access to jndi buy having an Initial Context defined which is the entry point to reach your jndi. later you can can access to the data source and start the other database operations.
 
m pa
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
turned out to be problem in SQL: statemetn

by removing the database name prefix, the exception went away

so instead of:


use:


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic