File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Connecting to Access Database Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Connecting to Access Database" Watch "Connecting to Access Database" New topic
Author

Connecting to Access Database

Ram Sateesh Talari
Greenhorn

Joined: Dec 03, 2003
Posts: 20
Hello Everyone...

In realtion to my previous mail...

I got another Idea...

without using the RMI...

well I mapped the database from one system onto a drive on my system and created a system dsn.

this is my code... it works if I give a select statement but doesn't if I give an insert statement

=========
code
=========

import java.sql.*;

public class rjdemo {

public static void main(String[] args) {
try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
//PETDB is System DSN
String url = "jdbc dbc ETDB";


java.sql.Connection c = DriverManager.getConnection(url,"ram","");

java.sql.PreparedStatement st1 = c.prepareStatement("insert into contact values('ram','ramemail')");
java.sql.PreparedStatement st = c.prepareStatement("select * from contact");
int i1 = st1.executeUpdate();
java.sql.ResultSet rs = st.executeQuery();
java.sql.ResultSetMetaData md = rs.getMetaData();
while(rs.next()) {
System.out.print("\nTUPLE: | ");
for(int i=1; i<= md.getColumnCount(); i++) {
System.out.print(rs.getString(i) + " | ");
}
}
rs.close();
} catch(Exception e) {
e.printStackTrace();
}
}
};

======
output
======

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Operation must
use an updateable query.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)

at rjdemo.main(rjdemo.java:16)

Thanks in advance

Cheers
Ram
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Odd. MS Access and the JDBC/ODBC bridge, eh? Great combination. No chance of using a proper database I don't suppose? Have you tried it with all the code for the SELECT part commented out? Maybe that's getting in the way. Your database is not in read-only mode or something, is it? Seems like a strange error message as INSERT/VALUES doesn't use a query!

Jules
Ram Sateesh Talari
Greenhorn

Joined: Dec 03, 2003
Posts: 20
Hi Jules

yeah exactly... it's in read-only mode.. but how do I change it to read-write state... ??

Cheers
Ram
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Well, I'm pretty sure that you can't do it from Java. It may be as simple as changing the read-only file attribute on the MDB file. Otherwise you'll probably need to look into MS Access permissions. I'm not familiar with those. Another alternative may be something you've set in your ODBC DSN.

Sorry I can't be of more help.

Jules
 
I agree. Here's the link: jrebel
 
subject: Connecting to Access Database
 
Similar Threads
SQLException on connect
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
error while entering the data into oracle database
Problem with SQL uqery or DSN
Invalid Transaction State