So I should move mysql-connector-java-5.1.18-bin.jar to a folder within in lib or move it to the java folder within lib?

A normal java project is structured:

Code:

<My-Project-Directory>
-- src
-- classes (though you may simpyl have the classes in the src depending on how you compile)
-- lib (this is where you dependent jar files go)

That's a basic structure. As it says, classes is optional and would involve using the -d option of javac. Without that then your class files will be placed beside the source files in the src folder (which may be fine for your needs).
That lib directory is the one I'm talking about.

Now, assuming you're in the <My-Project-Directory> directory you would do this to compile:
javac -cp ./src;./lib/*.jar <classes to compile eg src/somepackage/yourclass.java>

Basically if you work from a terminal just use the -cp option to define the classpath when you are executing your program using the java command. That was Toll tried to tell you on the previous answer. Just place the mysql.jar in the same location with your class.

For example:

java -cp .:mysql-connector-java-5.1.18-bin.jar ProgramOne

The dot symbol (.) is to add the current directory into the path so it can find your ProgramOne class.

04-13-2012, 12:10 PM

Tolls

Re: Mixing java and mysql

And that post reminded me, you'll probably have to check whether it's a ';' or a ':' for the separator inbetween different paths.
I can never remember.

04-13-2012, 12:14 PM

DarrylBurke

Re: Mixing java and mysql

Quote:

Originally Posted by Tolls

And that post reminded me, you'll probably have to check whether it's a ';' or a ':' for the separator inbetween different paths.
I can never remember.

Semicolon for Windows, colon for Linux. Mnemonic: many programmers believe Windows is half as good as Linux.

db <-- Windows user

04-13-2012, 06:47 PM

bad biddy

Re: Mixing java and mysql

Code:

[root@engagelinux ~]# java -cp .:mysql-connector-java-5.1.18-bin.jar ProgramOne
e.getMessage():You have an error in your SQL syntax; check the manual that corre
sponds to your MySQL server version for the right syntax to use near '?????????? ??????' at line 1
e.getLocalizedMessage():You have an error in your SQL syntax; check the manual t hat corresponds to your MySQL server version for the right syntax to use near '? ???????????????' at line 1
e.getStackTrace():[Ljava.lang.StackTraceElement;@1d8c3835

[root@engagelinux ~]# java -cp .:mysql-connector-java-5.1.18-bin.jar ProgramOne
e.getMessage():You have an error in your SQL syntax; check the manual that corre sponds to your MySQL server version for the right syntax to use near '?????????? ??????' at line 1
e.getLocalizedMessage():You have an error in your SQL syntax; check the manual t hat corresponds to your MySQL server version for the right syntax to use near '? ???????????????' at line 1
e.getStackTrace():[Ljava.lang.StackTraceElement;@1d8c3835

I repasted the error because it says it gets cut off when using the code tags.

04-13-2012, 07:03 PM

bad biddy

Re: Mixing java and mysql

I can compile and run local java files just fine.

When I compile the class file is created within the same directory. That is how I will keep it.

Now that we have a new java installed. I compiled it and tried to run the program
Here is the error code. Like before its not seeing the jdbc driver. I just have to setup the CLASSPATH and hopefully that fixes the driver issue.

Post #26 was not a ClassNotFoundException.
Launch your code with whatever command you used in that post, and then post the full stack trace.

04-16-2012, 04:41 PM

bad biddy

Re: Mixing java and mysql

I don't get what you mean.... that is how I run the program:

I just: java ProgramOne to run it. Those are the errors that popped up.

How do i show the full stack trace?

04-16-2012, 05:13 PM

Tolls

Re: Mixing java and mysql

Quote:

Originally Posted by bad biddy

Code:

[root@engagelinux ~]# java -cp .:mysql-connector-java-5.1.18-bin.jar ProgramOne
e.getMessage():You have an error in your SQL syntax; check the manual that corre
sponds to your MySQL server version for the right syntax to use near '?????????? ??????' at line 1
e.getLocalizedMessage():You have an error in your SQL syntax; check the manual t hat corresponds to your MySQL server version for the right syntax to use near '? ???????????????' at line 1
e.getStackTrace():[Ljava.lang.StackTraceElement;@1d8c3835

[root@engagelinux ~]# java -cp .:mysql-connector-java-5.1.18-bin.jar ProgramOne
e.getMessage():You have an error in your SQL syntax; check the manual that corre sponds to your MySQL server version for the right syntax to use near '?????????? ??????' at line 1
e.getLocalizedMessage():You have an error in your SQL syntax; check the manual t hat corresponds to your MySQL server version for the right syntax to use near '? ???????????????' at line 1
e.getStackTrace():[Ljava.lang.StackTraceElement;@1d8c3835

I repasted the error because it says it gets cut off when using the code tags.

This is post #26.
That exception is not the ClassNotFound one.
It is different.
How you ran your code here is the correct way, as it found your JDBC driver.

Its telling me that its unable to establish a connection to the database.

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:21)

04-17-2012, 09:36 AM

Tolls

Re: Mixing java and mysql

No it's not.
You are telling you it's unable to connect to the database.
Look at your catch block.