Results 41 to 54 of 54
Thread: Mixing java and mysql
- 04-17-2012, 10:30 AM #41
Re: Mixing java and mysql
Why do they call it rush hour when nothing moves? - Robin Williams
- 04-17-2012, 06:05 PM #42
Member
- Join Date
- Mar 2012
- Posts
- 51
- Rep Power
- 0
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.
- 04-17-2012, 06:11 PM #43
Member
- Join Date
- Mar 2012
- Posts
- 51
- Rep Power
- 0
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
- 04-17-2012, 09:55 PM #44
- 04-18-2012, 02:39 AM #45
Member
- Join Date
- Mar 2012
- Posts
- 51
- Rep Power
- 0
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?
- 04-18-2012, 07:15 AM #46
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?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-18-2012, 07:20 AM #47
Member
- Join Date
- Mar 2012
- Posts
- 51
- Rep Power
- 0
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
- 04-18-2012, 09:38 AM #48
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 04-18-2012, 05:21 PM #49
Member
- Join Date
- Mar 2012
- Posts
- 51
- Rep Power
- 0
Re: Mixing java and mysql
That is the code before the close bracket.Java Code:String sql = "INSERT INTO products (productName,supplierID,categoryID,unitPrice,) values ('Hard Disk',5555,6666,59.99)";
- 04-18-2012, 05:24 PM #50
Member
- Join Date
- Mar 2012
- Posts
- 51
- Rep Power
- 0
Re: Mixing java and mysql
Here is my actually table within mysql.... would I have to include productID too?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)
- 04-18-2012, 05:45 PM #51
Senior Member
- Join Date
- Apr 2012
- Posts
- 199
- Rep Power
- 0
- 04-18-2012, 05:55 PM #52
Member
- Join Date
- Mar 2012
- Posts
- 51
- Rep Power
- 0
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
- 04-18-2012, 06:04 PM #53
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 04-18-2012, 06:13 PM #54
Member
- Join Date
- Mar 2012
- Posts
- 51
- Rep Power
- 0
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.
Similar Threads
-
Is this a java issue? JApplet with MySQL access.. can't connect to mySQL
By cplredhartsock in forum Java AppletsReplies: 4Last Post: 03-04-2012, 11:26 PM -
Does latest JDK fully support mixing of heavy and light components
By hello2010 in forum AWT / SwingReplies: 7Last Post: 03-18-2011, 05:28 AM -
Mixing 2 audio stream threads for java mobile
By Severus in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 08-21-2010, 06:16 PM -
AWT/Swing Mixing Still and issue on MAC OSX?
By Confused in forum AWT / SwingReplies: 2Last Post: 02-21-2010, 08:34 PM -
Heavy and light component mixing
By Bojevnik in forum AWT / SwingReplies: 2Last Post: 08-13-2007, 11:23 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks