[prev in list] [next in list] [prev in thread] [next in thread]
List: jboss-user
Subject: [jboss-user] [Datasource Configuration] - java.sql.SQLException: [Microsoft][ODBC Microsoft Access D
From: m p <do-not-reply () jboss ! com>
Date: 2013-05-31 14:11:23
Message-ID: 2-820693-3-138118-1370009480415.jivesbs.jivemailuser () https://community ! jboss ! org
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
m p [https://community.jboss.org/people/mp_108] created the discussion
"java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find \
file"
To view the discussion, visit: https://community.jboss.org/message/820693#820693
--------------------------------------------------------------
Background:
I am developing in Eclipse and using Struts 2 framework to build and deploy .war file \
to http://www.coderanch.com/forums/f-63/JBoss JBoss. 4.2.3GA
There is an action class that I am using to insert a user into a database table - \
pretty simple stuff \
http://cache-www.coderanch.com/images/smilies/3b63d1616c5dfcf29f8a7a031aaa7cad.gif \
http://cache-www.coderanch.com/images/smilies/3b63d1616c5dfcf29f8a7a031aaa7cad.gif
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 (mailto:'mm.pp@yahoo.com)'); [STDOUT] java.sql.SQLException \
(http://docs.oracle.com/javase/7/docs/api/java/sql/SQLException.html): \
[Microsoft][ODBC Microsoft Access Driver] Could not find file \
*'C:\java\jboss-4.2.3.GA\bin\catNav.mdb'*.
*I am provide the full path to the database .mdb file but the exception is referring \
to file in jboss folder, which is does no exist. I am struggling to find a solution \
to resolve this. * The path, using either \\ or / file separators is validated as an \
exception occurs if invalid path is defined.
The code is below; I have the same code in a standalone Java program that executes \
successfully (I verify row was added) .... *but fails when running on JBoss* :(
public String execute() throws Exception {
//call Service class to store personBean's state in database
final String dbName = "catNav";
Connection con = null; // The connection to the database.
Statement stmt = null;
// The following code can throw errors, so they must be caught.
try{
// First, tell Java what driver to use and where to find it.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Next, create a connection to your data source.
// Specify that you are using the ODBC-JDBC Bridge.
// And specify the data source name from ODBC.
String database =
"jdbc:odbc:Driver={Microsoft Access Driver \
(*.mdb)};DBQ=C:/Users/mp/Documents/Work/JDBC/catNav.mdb;";
con = DriverManager.getConnection(database, "", "");
/* also tried:
con = DriverManager.getConnection("jdbc:odbc:catNavDB");
*/
// Create an SQL statement.
stmt = con.createStatement();
// Execute some SQL to create a table in your database.
// If the table already exists, an exception is thrown!
String sqlSt = "insert into " + dbName +
".USERS " +
"values('" + personBean.getFirstName() + "', " + // FIRST_NAME
"'" + personBean.getLastName() + "', " + // LAST_NAME
personBean.getAge() + ", " + // \
AGE
"'" + personBean.getEmail() + "'); " ; // EMAIL
// display SQL statment
System.out.println (">>>>>>>>>>" + sqlSt );
stmt.executeUpdate( sqlSt);
}
// Catch any exceptions that are thrown.
etc.
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/820693#820693]
Start a new discussion in Datasource Configuration at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077]
[Attachment #5 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; \
margin: 0; padding: 20px;">
<div>
<table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: \
1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; \
-webkit-border-radius: 6px;"> <tbody>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" \
style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: \
6px; -webkit-border-radius: 6px;"> <tbody>
<tr>
<td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px \
solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; \
-moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; \
-webkit-border-top-left-radius: 5px;">
<h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; \
margin: 0; display: block !important;">
<!-- To have a header image/logo replace the name below with your img tag \
-->
<!-- Email clients will render the images when the message is read so any \
image -->
<!-- must be made available on a public server, so that all recipients can \
load the image. -->
<a href="https://community.jboss.org/index.jspa" style="text-decoration: \
none; color: #E1E1E1">JBoss Community</a></h1> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; \
color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; \
-moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; \
-webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: \
17px; font-weight: normal;"> java.sql.SQLException: [Microsoft][ODBC Microsoft \
Access Driver] Could not find file </h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/mp_108">m p</a> in \
<i>Datasource Configuration</i> - <a \
href="https://community.jboss.org/message/820693#820693">View the full discussion</a> \
</span> <hr style="margin: 20px 0; border: none; background-color: #dadada; height: \
1px;">
<div class="jive-rendered-content"><p>Background: </p><p>I am developing in Eclipse \
and using Struts 2 framework to build and deploy .war file to <a \
class="jive-link-external-small" href="http://www.coderanch.com/forums/f-63/JBoss" \
rel="nofollow" target="_new">JBoss</a>. 4.2.3GA</p><p style="min-height: 8pt; height: \
8pt; padding: 0px;"> </p><p>There is an action class that I am using to insert a \
user into a database table - pretty simple stuff <a \
href="http://cache-www.coderanch.com/images/smilies/3b63d1616c5dfcf29f8a7a031aaa7cad.gif"><span> \
http://cache-www.coderanch.com/images/smilies/3b63d1616c5dfcf29f8a7a031aaa7cad.gif \
</span></a> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I \
get the following exception for executeUpdate() method. </p><p style="min-height: \
8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier \
new,courier;">DEBUG com.opensymphony.xwork2.DefaultActionInvocation.debug:68 - \
Executing action method = execute </span></p><p><span style="font-family: courier \
new,courier;"><span>[STDOUT] >>>>>>>>>>insert into \
catNav.USERS values('mm', 'pp', 88, </span><a class="jive-link-email-small" \
href="mailto:'mm.pp@yahoo.com" rel="nofollow" \
target="_blank">'mm.pp@yahoo.com</a><span>'); </span></span></p><p><span \
style="font-family: courier new,courier;">[STDOUT] <a \
class="jive-link-external-small" \
href="http://docs.oracle.com/javase/7/docs/api/java/sql/SQLException.html" \
rel="nofollow" target="_new">java.sql.SQLException</a>: [Microsoft][ODBC Microsoft \
Access Driver] Could not find file <span style="color: \
#ff0000;"><strong>'C:\java\jboss-4.2.3.GA\bin\catNav.mdb'</strong>.</span> \
</span></p><p style="min-height: 8pt; height: 8pt; padding: \
0px;"> </p><p><strong>I am provide the full path to the database .mdb file but \
the exception is referring to file in jboss folder, which is does no exist.  I \
am struggling to find a solution to resolve this.  </strong>The path, using \
either \\ or / file separators is validated as an exception occurs if invalid path is \
defined.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The \
code is below; I have the same code in a standalone Java program that executes \
successfully (I verify row was added)  .... <span style="color: \
#ff0000;"><strong>but fails when running on JBoss</strong></span> <span> :( \
</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span \
style="font-family: courier new,courier;"> public String execute() throws Exception \
{</span><br/><span style="font-family: courier new,courier;">   \
</span><br/><span style="font-family: courier new,courier;">  //call Service \
class to store personBean's state in database</span><br/><span style="font-family: \
courier new,courier;">  final String dbName = "catNav";</span></p><p><span \
style="font-family: courier new,courier;">  Connection con = null; // The \
connection to the database.</span><br/><span style="font-family: courier \
new,courier;">  </span><br/><span style="font-family: courier \
new,courier;">  Statement stmt = null;</span><br/><span style="font-family: \
courier new,courier;">  </span><br/><span style="font-family: courier \
new,courier;">  // The following code can throw errors, so they must be \
caught.</span><br/><span style="font-family: courier new,courier;">  \
try{</span></p><p><span style="font-family: courier new,courier;">   // \
First, tell Java what driver to use and where to find it.</span><br/><span \
style="font-family: courier new,courier;">   \
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");</span></p><p><span style="font-family: \
courier new,courier;">   </span><br/><span style="font-family: courier \
new,courier;">   // Next, create a connection to your data \
source.</span><br/><span style="font-family: courier new,courier;">   // \
Specify that you are using the ODBC-JDBC Bridge.</span><br/><span style="font-family: \
courier new,courier;">   // And specify the data source name from \
ODBC.</span><br/><span style="font-family: courier new,courier;">   String \
database = </span><br/><span style="font-family: courier \
new,courier;">             \
"jdbc:odbc:Driver={Microsoft Access Driver \
(*.mdb)};DBQ=C:/Users/mp/Documents/Work/JDBC/catNav.mdb;";</span><br/><span \
style="font-family: courier new,courier;">   </span><br/><span \
style="font-family: courier new,courier;">   con = \
DriverManager.getConnection(database, "", "");</span></p><p><span style="font-family: \
courier new,courier;">   /* also tried:</span><br/><span \
style="font-family: courier new,courier;">   con = \
DriverManager.getConnection("jdbc:odbc:catNavDB");</span><br/><span \
style="font-family: courier new,courier;">   */</span><br/><span \
style="font-family: courier new,courier;">   </span><br/><span \
style="font-family: courier new,courier;">   // Create an SQL \
statement.</span><br/><span style="font-family: courier new,courier;">   \
stmt = con.createStatement();</span><br/><span style="font-family: courier \
new,courier;">  </span><br/><span style="font-family: courier \
new,courier;">   // Execute some SQL to create a table in your \
database.</span><br/><span style="font-family: courier new,courier;">   // \
If the table already exists, an exception is thrown!</span><br/><span \
style="font-family: courier new,courier;">   String sqlSt = "insert into " \
+ dbName +</span><br/><span style="font-family: courier \
new,courier;">     ".USERS " +</span><br/><span \
style="font-family: courier new,courier;">     "values('" + \
personBean.getFirstName() + "', " +  // FIRST_NAME</span><br/><span \
style="font-family: courier new,courier;">     "'" + \
personBean.getLastName() + "', " \
+          // LAST_NAME</span><br/><span \
style="font-family: courier new,courier;">     \
personBean.getAge() + ", " \
+                      \
// AGE</span><br/><span style="font-family: courier \
new,courier;">     "'" + personBean.getEmail() + "'); "  \
;           // \
EMAIL</span><br/><span style="font-family: courier new,courier;">   \
</span><br/><span style="font-family: courier new,courier;">   // display \
SQL statment</span><br/><span style="font-family: courier new,courier;">   \
System.out.println (">>>>>>>>>>" + sqlSt \
);</span><br/><span style="font-family: courier new,courier;">   \
</span><br/><span style="font-family: courier new,courier;">   \
stmt.executeUpdate( sqlSt);</span><span style="font-family: courier \
new,courier;">  </span><br/><span style="font-family: courier \
new,courier;">   </span><br/><span style="font-family: courier \
new,courier;">   }</span><br/><span style="font-family: courier \
new,courier;">   // Catch any exceptions that are thrown.</span><br/><span \
style="font-family: courier new,courier;">   \
etc.</span><br/>                       \
</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a \
href="https://community.jboss.org/message/820693#820693">going to Community</a></p> \
<p style="margin: 0;">Start a new discussion in Datasource Configuration at <a \
href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic