*
The moose likes JDBC and the fly likes help wanted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "help wanted" Watch "help wanted" New topic
Author

help wanted

Lavanya Raman
Greenhorn

Joined: Feb 27, 2001
Posts: 4
hi,
i am using MS Access as database and jdk 1.3 and i created a dsn called
akiladb and no description in the odbc dialog box. I created a directory called akiladb and storing a table employee in that.
The table employee contains name , empno,deptno,salary as fields and i have populated the table with 4 rows. i have written a program which is below and it compiles fine but gives runtime error as follows
[Microsoft][ODBC Microsoft Access Driver}
It may not be a database that your application recongnizes or the file may be corrupt.
This is the first time i am writing a JDBC application. Please correct me where i am wrong

The program is as follows.

import java.sql.*;
public class CreateCoffee {
public static void main(String args[]) {
String url = "jdbc dbc:akiladb";
Connection con;
String updateString;
updateString = "update employee " +
"set deptno=135 " +
"where name like 'akila'" ;
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(updateString);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
Check out your DataSource in the ODBC Datasource Administrator.
Does your database name appear in the database frame
(eg. Database: c:\akiladb\akiladb.mdb)?
Lavanya Raman
Greenhorn

Joined: Feb 27, 2001
Posts: 4
hi joe,
Thanks for your reply. my database appears in the ODBC Microsoft Access setup with the data source name as akiladb, description (nothing)
database
c:\akiladb\akiladb.mdb
and the system database selected as none.

please correct me wherever i am wrong.
thanks
akila
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
Your java code looks fine, the problem is on the Access side. You may want to verify that you can still view/update your data within MS Access (the error states that the data may be corrupt). If this is the problem then either try to use the REPAIR option or recreate the database and tables.
Keep me posted,
Joe
[This message has been edited by Joe Paolangeli (edited March 02, 2001).]
Lavanya Raman
Greenhorn

Joined: Feb 27, 2001
Posts: 4
Hi Joe,
I am able to read the database from MS access.
The database I have is in a directory c:\akiladb\db1.mdb
In my program, I have defined as follows :
String url = "jdbc dbc:akiladb";
and I am trying to connect to this to access
one of the .mdb files (db1.mdb) in my c:\akiladb. Is this
correct or do I need to specify absolute paths?
Thanks,
Akila.
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
The path to the database is set in the ODBC Source Administrator.
As you stated before your database is located in the c:\akiladb directory. I am a little confused about the name of your database. Is the name db1.mdb or akiladb.mdb? Please verify that the correct database name is specified in the ODBC Source Administrator.
Keep me posted,
Joe
Lavanya Raman
Greenhorn

Joined: Feb 27, 2001
Posts: 4
hi Joe,
thanks for the reply. It was a mistake on my part. I have stored
my table in a different database and in the odbc setup i had specified a different database and so the error.i understood my mistake from your last reply.
Thanks a lot
akila
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help wanted