Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting to Access Database

 
Ram Sateesh Talari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic