This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception in thread "main" java.sql.SQLException:" Watch "Exception in thread "main" java.sql.SQLException:" New topic
Author

Exception in thread "main" java.sql.SQLException:

Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Hey I am facing the below mentioned problems.. so pls see it and let me know.

My programme is this
import java.sql.*;
public class accbase1
{
public static void main(String args[]) throws ClassNotFoundException,SQLException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbcdbc:accdsn");
Statement st=cn.createStatement();
int n=st.executeUpdate("create table students1(sno integer primary key,sname text(20),courses text(30))");
if( n == -1 )
System.out.println("table is created..");

st.close();
cn.close();

}
}



And I am getting this exception

D:\EX\jdbc>javac accbase2.java

D:\EX\jdbc>java accbase2
Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3074)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:3
23)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at accbase2.main(accbase2.java:7)
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

Well for starts, the stack trace indicates the problem is with your getConnection() line so everything after that is irrelevant.

If I had to guess I'd say your ODBC entry was not set up to access the proper access file, although I'm not an ODBC person (no chance you could use a real db?) so someone else will have to take a shot.


My Blog: Down Home Country Coding with Scott Selikoff
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Follow this link Connecting to a Database with JDBC
Hope it will helpful to you.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Originally posted by Scott Selikoff:
Well for starts, the stack trace indicates the problem is with your getConnection() line so everything after that is irrelevant.

If I had to guess I'd say your ODBC entry was not set up to access the proper access file, although I'm not an ODBC person (no chance you could use a real db?) so someone else will have to take a shot.



Yes Sir,

I did create the dsn name and i run the same programme some time back.. but it is not working now... please help me out
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.sql.SQLException: