File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "A question about JDBC database access" Watch "A question about JDBC database access" New topic

A question about JDBC database access


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,
import java.sql.*;
import java.util.*;
public class test {

private static Connection toCon = null;
public static void main(String[] args) {
try {
String data = "jdbc dbc:TEST";
toCon = DriverManager.getConnection(data, "", "");
Statement st = toCon.createStatement();
catch (Exception e) {
System.out.println("Warning Transfer Incomplete....");
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: 15302

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:
subject: A question about JDBC database access
It's not a secret anymore!