Page 3 of 3 FirstFirst 123
Results 41 to 54 of 54
Like Tree1Likes

Thread: Mixing java and mysql

  1. #41
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Mixing java and mysql

    Quote Originally Posted by Tolls View Post
    No it's not.
    You are telling you it's unable to connect to the database.
    I know that wasn't meant to be funny, but I got a good laugh out of it.

    @bad biddy: no offense. Another's mistakes are sometimes hilarious. If you feel like revenge, watch and wait for a chance to laugh at me :)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  2. #42
    bad biddy is offline Member
    Join Date
    Mar 2012
    Posts
    51
    Rep Power
    0

    Default Re: Mixing java and mysql

    Lol its all good :) I'm still learning.

    What I dont get is it's basically setup the exact same as ProgramOne but yet says it cannot connect to the database.

    I'll look it over more later since im in class now..... but our java professor told us to bring our laptops wednesday and friday so if we are having any problems we can try to figure them out.


    P.S. No one has ProgramOne done.... besides me pretty much because you guys helped me out so much.

    Now to get ProgramTwo

    Pretty sure I got program three to work.

  3. #43
    bad biddy is offline Member
    Join Date
    Mar 2012
    Posts
    51
    Rep Power
    0

    Default Re: Mixing java and mysql

    Java Code:
    [root@engagelinux ~]# java -cp .:mysql-connector-java-5.1.18-bin.jar ProgramTwo
    Unable to establish connection with the database.
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your 
    
    
    MySQL server version for the right syntax to use near ') values ('Hard Disk',5555,6666,59.99)' at line 1
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
            at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
            at com.mysql.jdbc.Util.getInstance(Util.java:386)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
            at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
            at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
            at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
            at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1749)
            at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1666)
            at ProgramTwo.main(ProgramTwo.java:20)

    Is there a problem with the way I am trying to insert the information into the table?

    Java Code:
    MySQL server version for the right syntax to use near ') values ('Hard Disk',5555,6666,59.99)' at line 1

  4. #44
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Mixing java and mysql

    Quote Originally Posted by bad biddy View Post
    ... but yet says it cannot connect to the database.
    Read Tolls' last response. What says it cannot connect to the database? Does that statement have any root in fact, or is it a bad guess?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #45
    bad biddy is offline Member
    Join Date
    Mar 2012
    Posts
    51
    Rep Power
    0

    Default Re: Mixing java and mysql

    I don't get what you two are trying to get me to provide. I see that you want me to stick to the printStackTrace but isn't it already implemented into my code so when a error arises it displays whats wrong?

  6. #46
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Mixing java and mysql

    Please stick to the forum threads, not PMs, for your technical questions. You'll get answers when people get around to it. No later and no sooner.

    Are you still blind to the fact that it is your code that makes an unsubstantiated claim of inability to connect to the database?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #47
    bad biddy is offline Member
    Join Date
    Mar 2012
    Posts
    51
    Rep Power
    0

    Default Re: Mixing java and mysql

    Tolls said that my sql is wrong.... I tried comparing it to ProgramOne and ProgramThree but I can't find any differences in the code/sql

  8. #48
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Mixing java and mysql

    I also said that it was your code that says it can't connect.
    That first println() in the catch(SQLException) block is the one claiming you aren't connecting.
    It is incorrect, since SQLExceptions (as in this case) are not all about failing to connect.
    Remove that line as it is causing you to get confused as to what the real problem is.

    As for the SQL, look at it around the point the error says there's a problem. They'r enot always this accurate, but in this case it's spot on. What is there just before that close bracket?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #49
    bad biddy is offline Member
    Join Date
    Mar 2012
    Posts
    51
    Rep Power
    0

    Default Re: Mixing java and mysql

    Java Code:
     String sql = "INSERT INTO products (productName,supplierID,categoryID,unitPrice,) values ('Hard Disk',5555,6666,59.99)";
    That is the code before the close bracket.

  10. #50
    bad biddy is offline Member
    Join Date
    Mar 2012
    Posts
    51
    Rep Power
    0

    Default Re: Mixing java and mysql

    Java Code:
    mysql> select * from products;
    +-----------+----------------+------------+------------+-----------+
    | productID | productName    | supplierID | categoryID | unitPrice |
    +-----------+----------------+------------+------------+-----------+
    |         1 | Flash Disk     |       1000 |       2000 |   10.0000 |
    |         2 | SSD Disk       |       1000 |       2000 |  100.0000 |
    |         3 | SD Card        |       1000 |       2000 |   15.0000 |
    |         4 | USB Drive      |       1000 |       2000 |   29.0000 |
    |         5 | Micro SD Drive |       1000 |       2000 |   10.0000 |
    |         6 | Head Phone     |       1000 |       2001 |    9.9900 |
    +-----------+----------------+------------+------------+-----------+
    6 rows in set (0.00 sec)
    Here is my actually table within mysql.... would I have to include productID too?

  11. #51
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: Mixing java and mysql

    Quote Originally Posted by bad biddy View Post
    It works!!!!

    Java Code:
    [root@engagelinux ~]# java -cp .:mysql-connector-java-5.1.18-bin.jar ProgramOne
    PRODUCT ID      PRODUCT NAME    SUPPLIER ID     CATEGORY ID     UNIT PRICE
    1       Flash Disk      1000    2000    10.0
    2       SSD Disk        1000    2000    100.0
    3       SD Card 1000    2000    15.0
    4       USB Drive       1000    2000    29.0
    5       Micro SD Drive  1000    2000    10.0
    6       Head Phone      1000    2001    9.99
    I just gotta edit the code now for the project.
    Hello Bad Biddy,

    In post #37, you said "It works!!!!". How did you get it to work?

    Stephen

  12. #52
    bad biddy is offline Member
    Join Date
    Mar 2012
    Posts
    51
    Rep Power
    0

    Default Re: Mixing java and mysql

    This post is for programOne. I am currently working on getting programTwo to work.....

    i used this command and got it to work

    Java Code:
    [root@engagelinux ~]# java -cp .:mysql-connector-java-5.1.18-bin.jar ProgramOne

  13. #53
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Mixing java and mysql

    INSERT INTO products (productName,supplierID,categoryID,unitPrice,) values ('Hard Disk',5555,6666,59.99)

    And you don't see the problem?
    Right where the exception said there was a problem?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #54
    bad biddy is offline Member
    Join Date
    Mar 2012
    Posts
    51
    Rep Power
    0

    Default Re: Mixing java and mysql

    Java Code:
    [root@engagelinux ~]# java -cp .:mysql-connector-java-5.1.18-bin.jar ProgramTwo
    1 rows updated.

    Oh my gosh i cant believe i didnt see that comma...... I just have to edit the code to insert three different products which should be easy now that it works.... Thanks so much Tolls!

    I'll post in here if i have problems adding the three different products.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Replies: 4
    Last Post: 03-04-2012, 11:26 PM
  2. Replies: 7
    Last Post: 03-18-2011, 05:28 AM
  3. Mixing 2 audio stream threads for java mobile
    By Severus in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-21-2010, 06:16 PM
  4. AWT/Swing Mixing Still and issue on MAC OSX?
    By Confused in forum AWT / Swing
    Replies: 2
    Last Post: 02-21-2010, 08:34 PM
  5. Heavy and light component mixing
    By Bojevnik in forum AWT / Swing
    Replies: 2
    Last Post: 08-13-2007, 11:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •