Results 1 to 12 of 12

Thread: Database not being populated....

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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.

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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>://hostnameort/subsubname
    but in your case im not too sure because i notice that you are using the jdbcdbc bridge and not the MySql JConnector which i use.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  4. #4

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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?

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Database not being populated....

    JConnector is just the offical driver for MySql. What backend are you using? Sounds like Access.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  7. #7

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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...?

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  9. #9

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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)

  10. #10
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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),
    );

  11. #11
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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

  12. #12

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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
  •  



Click Here to Expand Forum to Full Width