Invalid Path in JDK1.3.1&JDBC-ODBC Connection on Windows NT 4
Hi, Please help me in solving the problem of Invalid Path in JDK1.3.1&JDBC-ODBC Connection on Windows NT 4, when the following code was run:
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/jdk1.3.1/jdbc2/CreateCoffees.mdb";
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME varchar(32), " +
"SUP_ID int, " +
"PRICE float, " +
"SALES int, " +
"TOTAL int)";
Statement stmt;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, "", "");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
The complete error message is SQLException:[Microsoft][ODBC Microsoft Driver] '(unknown)' is not a valid path. Make sure that the path is spelled correctly and that you are connected the server on which the file resides. I had specified the path in the following way: set CLASSPATH=C:\jdk1.3.1\jdbc2;C:\path\jdk1.3.1\jdbc2, and set Path=C:\jdk1.3.1\jdbc2.
Please help and tell me what I did wrong in the program code or in CLASSPATH/Path.
Thanks,
BigOcean
[1626 byte] By [
BigOcean] at [2007-9-26 3:09:10]

That doesn't look like a valid file path for a windows operating system - it should use backslashes.
Hi, jschell.
If I used the 'backslash' in String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ= C:\jdk1.3.1\jdbc2\CreateCoffees.mdb";. I got an error message: Illegal escape character, when it was compiled. If I used the 'slash' in that statement, it was compiled okay, but it had the "Invalid Path" problem in the execution. Any more ideas to solve this problem?
Any help is appreciated.
Thanks,
BigOcean
> If I used the 'slash' in that statement, it was compiled okay,
>but it had the "Invalid Path" problem in the execution. Any more ideas to solve this problem?
You can't use a single backslash like that in a string. You have to escape it.
String path = "DBQ= C:\\jdk1.3.1\\jdbc2\\CreateCoffees.mdb"
Thanks, jschell. I used the String path = "DBQ= C:\\jdk1.3.1\\jdbc2\\CreateCoffees.mdb" in my program code:
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)";
String path = "DBQ= C:\\jdk1.3.1\\jdbc2\\CreateCoffees.mdb";
}
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME varchar(32), " +
"SUP_ID int, " +
"PRICE float, " +
"SALES int, " +
"TOTAL int)";
Statement stmt;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, "", "");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
*************************
When it was compiled, I got 6 errors:
C:\jdk1.3.1\jdbc2>javac CreateCoffees.java
CreateCoffees.java:9: <identfier> expected
createString = "create table COFFEES " +
CreateCoffees.java:16: illegal start of type
try {
CreateCoffees.java:30: <identifier> expected
}
CreateCoffees.java:32: 'class' or 'interface' expected
}
CreateCoffees.java:32: 'class' or 'interface' expected
}^
CreateCoffees.java:9: cannot resolve symbol
symbol : class createString
location : class CreateCoffees
createString = "create table COffees " +
6 errors
***********************
I do not know how to correct them. Please help again.
Thanks,
BigOcean
Those are not jdbc problems they are simple java syntax errors.
The compiler tells you the problem in on line 9. Look at line 9. I would start with trying to figure out why you have a statement outside of a method block. Line 8 is a declaration, line 9 is a statement. Declarations work outside a method, statements don't.
Hi, jschell.
I made changes in the following code and it was compiled okay, but I got the same "Invalid Path" error again.
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)";
String path = "DBQ= C:\\jdk1.3.1\\jdbc2\\CreateCoffees.mdb";
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME varchar(32), " +
"SUP_ID int, " +
"PRICE float, " +
"SALES int, " +
"TOTAL int)";
Statement stmt;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, "", "");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
Please help and tell me what wrong with the current code.
Thanks,
BigOcean
hello
you have to create a DSN for the same to access this..
It's like this..
go to the "control panel" , out there click on " ODBC 32 bit" or something like that.. then create a new DSN for urself by clicking add...and give the name to it and provide the driver for it..and u'd be asked to provide the database name too...
now use this DSN name instead of the your "{C:\..etc}"
hope this helps... haven't worked with this at all .. only worked with oracle( with their drivers..it's simpler..!!? ) but this is what i could remember from my class room lessons... all the best... hope it helps...
premal
Thanks, genghiz. I have created a DSN in the control panet for this project - FooDSN for the CreateCoffees.mdb file.I think there is a problem in this statment: String path = "DBQ= C:\\jdk1.3.1\\jdbc2\\CreateCoffees.mdb";. I even do'nt know what DBQ standards for and its relationship with JDBC2. I hope JDBC2 experts can kindly give me a solution.
BigOcean
well for Access just stick your DSN name and do not put what you have mentioned below... it should work... hope it does....
that's all u have to do...
replace your c:\... etc with your DSN name... and don't forget to map your DSN name with the .mdb file... hope you know what i'm talking about ....
- you don't need this replace with DSN -
: String path = "DBQ=
> C:\\jdk1.3.1\\jdbc2\\CreateCoffees.mdb";. I even do'nt
> know what DBQ standards for and its relationship with
> JDBC2. I hope JDBC2 experts can kindly give me a
> solution.
>
> BigOcean
Big Ocean was trying to access his access db by it's file!
If he wants to access it by an odbc driver, he's got to try this:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
String url = "jdbc:odbc:ademeregion" ;
Connection con = DriverManager.getConnection( url , "" , "" ) ;
Statement stmt = con.createStatement();
ResultSet itom = stmt.executeQuery( "SELECT * FROM TABLE" ) ;
I'm using this code and it's working.
But if I want to connect to the db by it's file, like BigSea at the biginning, how should I code it?
Thanks.
Hi genghiz and sylvain.barbot. I tried to create a new mdb file via jdbc2-odbc, not to access the existing mdb file. Originally I copied the code from the Example in Pages 100-104, JDBC API Tutorial and Reference, 2nd Edition: Universal Data Access for the Java 2 Platform (Java Series) by S. White, M. Fisher, R. Cattell, G. Hamilton, and M. Harper (June, 1999) and replaced "url" with "JDBC2-ODBC". Hope url and JDBC2-ODBC experts can tell me why "Invalid Path" occurred.
BigOcean
Thank you to you.I seemed to be having similar problem; but I found the following to work correctly on NT. Compiled and ran perfect.... Thanks.
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Address/Address.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(url, "", "");