aspose file tools*
The moose likes JDBC and the fly likes A question about JDBC database access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "A question about JDBC database access" Watch "A question about JDBC database access" New topic
Author

A question about JDBC database access

wenting
Greenhorn

Joined: Dec 06, 2002
Posts: 2
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

Joined: Sep 28, 2002
Posts: 86
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.


We make a living by what we get, we make a life by what we give!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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.


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question about JDBC database access