|
-
Feb 6th, 2005, 11:51 AM
#1
Thread Starter
Frenzied Member
Database not being populated....
I have the datasoure and drivers set up, but for some reason this code is not updating the database.
Code:
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.
-
Feb 8th, 2005, 11:23 PM
#2
Dazed Member
Re: Database not being populated....
Im not sure if your datasource is right. Im pretty sure you have to follow a pattern like the following jdbc:<subprotocol>://hostname ort/subsubname
but in your case im not too sure because i notice that you are using the jdbc dbc bridge and not the MySql JConnector which i use.
-
Feb 9th, 2005, 04:31 AM
#3
Re: Database not being populated....
Whatever comes after the subprotocol is entirely up to the subprotocol handler. MySQL requires the URL. ODBC requires an ODBC connection string. Oracle requires something really weird. Etc...
Have you tested the return value of executeUpdate()? Have you checked Connection.getWarnings()?
Last edited by CornedBee; Feb 9th, 2005 at 04:35 AM.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 9th, 2005, 06:14 AM
#4
Thread Starter
Frenzied Member
Re: Database not being populated....
When I created the table through code, I accidently put the data types after the name of the field. I also changed the statement to this:
Code:
createStatement = "CREATE TABLE Coffeebreak(Name String PRIMARY KEY, " +
"int ID_NUM, int Pay)";
It did populate the database, but it still throws the sql exception...
Dillenger, what is this sql JConnector?
-
Feb 9th, 2005, 11:18 AM
#5
Dazed Member
Re: Database not being populated....
JConnector is just the offical driver for MySql. What backend are you using? Sounds like Access.
-
Feb 9th, 2005, 11:40 AM
#6
Re: Database not being populated....
Something's still not right with that create table statement. In the first column, you have the field name first, in the other columns the type.
According to the MySQL docs, the name must come first. And I don't think Access deviates that strongly from standard SQL.
http://dev.mysql.com/doc/mysql/en/create-table.html
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 9th, 2005, 03:24 PM
#7
Thread Starter
Frenzied Member
Re: Database not being populated....
for some reason, when I put String infront of name, I get an sql exception saying syntax error in field definition...When I had the data type after, it just threw a sql exception saying general error...?
-
Feb 9th, 2005, 03:36 PM
#8
Re: Database not being populated....
Well, I don't have an Access SQL reference at hand. I found this:
http://msdn.microsoft.com/library/de.../acfundsql.asp
But it's more of a tutorial. The reference is supposed to come with Access.
Are you sure String is a valid data type? It's not a standard SQL type, anyway.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 9th, 2005, 05:18 PM
#9
Thread Starter
Frenzied Member
Re: Database not being populated....
I don't think that String is a standard type...I looked at one of my books, and for each String field they had, they just declared the field name and had this after it: VARCHAR(30)......I tried putting this after the fieldname, but it still had the same error...In the book they also had the datatype after the fieldname(which doesn't make much sense, but it's suppose to work that way)
-
Feb 10th, 2005, 10:32 PM
#10
Dazed Member
Re: Database not being populated....
String is not a datatype in MySql you have to use varchar()
Code:
create table employee(
empfname varchar(25),
emplname varchar(30),
);
-
Feb 10th, 2005, 10:34 PM
#11
Dazed Member
Re: Database not being populated....
This might help you instead of looking through the documentation of your specific database. I know MySql's doc are extremely long.
http://www.functionx.com/sql/index.htm
-
Feb 11th, 2005, 06:23 AM
#12
Thread Starter
Frenzied Member
Re: Database not being populated....
Thanks dillenger, I'll check that website out..Glad you pointed it out too, because it's going to come in handy later.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|