| | |
Database not being populated....
![]() |
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
I have the datasoure and drivers set up, but for some reason this code is not updating the database.
I'm sure that the problem has to be with what's in bold, but it looks right...
I do have the code that created the table if you need that. It created three columns, Name, ID_NUM, and Pay...But none of those are being populated.
import java.sql.*;
public class TestCreateCoffeeTable
{
public TestCreateCoffeeTable()
{
}
public static void main(String[] args)
{
try
{
String createStatement;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSource = "jdbc:odbc:Coffeebreak";
Connection con = DriverManager.getConnection(dataSource);
Statement statement1 = con.createStatement();
String insert;
//add the info
insert = "INSERT INTO Coffeebreak VALUES( 'Bob', 24, 23)";
statement1.executeUpdate(insert);
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch(SQLException sqle)
{
System.err.println(sqle);
}
catch(Exception e)
{
System.err.println(e);
}
}
}I'm sure that the problem has to be with what's in bold, but it looks right...
I do have the code that created the table if you need that. It created three columns, Name, ID_NUM, and Pay...But none of those are being populated.
Are you getting any errors?
Unless you have a DSN named exactly the same as the table you're trying to update that may be your problem.
Also remember that (unlike SQL standard...) MSAccess I think uses case sensitive table and field names.
The most correct form of the insert statement would also include the field names in the statement to ensure that they're in the order you want.
Furthermore you may or may not need to add a semicolon to the SQL statement. Officially it shouldn't be needed but some drivers and databases aren't as nice as others
So your SQL should be INSERT INTO Coffeebreak (Name, ID_NUM, Pay) VALUES ('Bob', 24, 23)
Unless you have a DSN named exactly the same as the table you're trying to update that may be your problem.
Also remember that (unlike SQL standard...) MSAccess I think uses case sensitive table and field names.
The most correct form of the insert statement would also include the field names in the statement to ensure that they're in the order you want.
Furthermore you may or may not need to add a semicolon to the SQL statement. Officially it shouldn't be needed but some drivers and databases aren't as nice as others

So your SQL should be INSERT INTO Coffeebreak (Name, ID_NUM, Pay) VALUES ('Bob', 24, 23)
there is no createStatement() method taking a String...
What's the returnvalue you get from executeUpdate()? That's the number of records the database reports inserted.
If it's 1 and afterwards you don't see them appearing, autocommit may be off on the database.
Either do an explicit commit or set autocommit to on.
What's the returnvalue you get from executeUpdate()? That's the number of records the database reports inserted.
If it's 1 and afterwards you don't see them appearing, autocommit may be off on the database.
Either do an explicit commit or set autocommit to on.
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
I tried something like this:
System.out.println(statement1.executeUpdate(insert));
but it throws an sql exception saying simply "general error"
If I shouldn't use System.out for checking the return val, please let me know how I should be checking it.. I do have the code that created the table, so I could post that if you think it's something in effect to it..
System.out.println(statement1.executeUpdate(insert));
but it throws an sql exception saying simply "general error"
If I shouldn't use System.out for checking the return val, please let me know how I should be checking it.. I do have the code that created the table, so I could post that if you think it's something in effect to it..
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
I finally figured it out.. When I created the table, I specified the data type after the name of the field...I don't know how I could be that stupid(which is why I'm blaming my computer this time)... It did update the single test field like I wanted, but for some reason the same sql exception is being thrown. I guess it doesn't matter much now, but do you have any idea why it's still being thrown.
![]() |
Similar Threads
- database connectivity in vb (Visual Basic 4 / 5 / 6)
- Getting geo coordinates for an access database of street addresses (Visual Basic 4 / 5 / 6)
- how to insert data from dataset into database (VB.NET)
Other Threads in the Java Forum
- Previous Thread: Threads
- Next Thread: why do i compile wrong of SDK?
| Thread Tools | Search this Thread |
account android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer homework html ide image inheritance integer integration intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux loop method midlethttpconnection migrate mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program property ria scanner server set sharepoint smart sms smsspam sourcelabs splash sql sqlite subclass support swing testautomation textfield threads tree trolltech unlimited utility windows






