• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about JDBC database access

 
wenting
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java program which should insert one record into a table in a Access database. I set up ODBC in the control panel->Data Sources(ODBC). The DSN for this database is TEST. The program seems working. However, it doesn't insert the record into that table. Strangely, when I use the same program, just change DSN to another database, it works fine. I just cannot think a reason which might cause the problem.
many many thanks,
wendy
import java.sql.*;
import java.util.*;
public class test {

private static Connection toCon = null;
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String data = "jdbc dbc:TEST";
toCon = DriverManager.getConnection(data, "", "");
Statement st = toCon.createStatement();
st.executeUpdate("INSERT INTO IPD_META_ANALYSIS (MA_ID,TITLE) VALUES ('1205','TEST')");
}
catch (Exception e) {
System.out.println("Warning Transfer Incomplete....");
System.out.println(e);
}
}
}
 
Sam Moran
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a stupid question, but will the DB allow to insert a record without the program that you wrote? I have been working with a DB that is set so that I can only read from it not add or delete. I hope this helps.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When trying to insert the data, if the DB is not allowing the insert, an exception should be thrown. Are you getting any error messages? This might better aid in determing the problem as your code looks fine and it seems to work on other Datbases.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic