I havent yet started to do the code.i dont know where to start.I have just tested a simple code to print.but i am getting the result as Cannot connect to database server which is in catch.
public class Connect { public static void main (String[] args) { String createString;
Either the database does not exist, or the password is wrong.
I have just tried your code, only changing the password and the query (into "SHOW TABLES"), and it printed "Database connection established", followed by "Database connection terminated".
I think the 'database' is not within Java environment and its totally a different system, it needs some 'intermediate' person to talk with. That's what they call as a 'Driver'.
Have you given a thought about it?
Beforehand, had you have a database in your machine and created the tables first of all?
That's what i had told already. You need to have the "mysql-connector" jar file in your classpath for both compilation and running.
preethi Ayyappan
Ranch Hand
Joined: Oct 04, 2007
Posts: 518
posted
0
Now I had installed my sql jar files 1.jdbc2_0-stdext.jar 2.jta-spec1_0_1.jar 3.jdbc-connector.jar 4.mysql-connector.jar 5.mysql-connector-java-3.0.17-ga-bin.jar
in the path /usr/java/jdk1.6.0_03/lib/mysql-connector-java-3.0.17-ga/lib. my java file is in /usr/java/jdk1.6.0_03/bin.Is it correct? Now also i amgetting the same error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver pls guide me.
Thanks.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35258
7
posted
0
It doesn't matter in which directory you put the file - it needs to be in your classpath. You might run your program like
preethi Ayyappan
Ranch Hand
Joined: Oct 04, 2007
Posts: 518
posted
0
I have tried your code to run like this: java -classpath .:/usr/java/jdk1.6.0_03/lib/mysql-connector-java-3.0.17-ga/lib/mysql-connector-java-3.0.17-ga-bin.jar Connect.
But i am getting the following error:
java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory
preethi Ayyappan
Ranch Hand
Joined: Oct 04, 2007
Posts: 518
posted
0
Now i put the jar files in correct path and i got the result.