Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC, mysql connector/j, face a problem to connect mysql 5.1 and JSE.

 
Mohammad Ashrafuddin Ferdousi
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Think you are doing well. I am a beginner in java. So, i faced a problem now. can you please help? I am trying to connect with mysql using connector/j(latest). I use:

1] mysql connector/j
2] mysql 5.1(It was installed automatically when i am installing xampp)
3] java 6
4] eclipse gallilio for JEE developers.

What i do:

1]at first i unzip the mysql connector/j.zip file on C:\

2] write the code like this way:

DB CLASS:


GetMySqlConnection(main) Class:



3]

a] As i use windows xp, i add the classpath by going property of "my computer", clicked on "Advanced" tab,clicked "Environment Variable" and create a new variable,"CLASSPATH" and the value is,"C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8-bin.jar;".It does not work. Throws an exception by eclipse console mode. that is:



b] So, i delete the classpath variable from "environment variables". My second attempt was, Eclipse->Window->Preference->java->Build Path->Classpath Variables. Then click on "new" button and set "Name" and "Path" as "classpath" and "C:/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar" by browsing the file. Again i run the code and found the same error:



I know most of you know the solve. Perhaps, there is a problem that system can not found the driver or the "connector/j" and java 6 version is not compatible each other. But i am not sure what happened. Please help me.


A little bit long description i written down here, i know. If there is some mistakes i am so sorry. Have a nice day.

Thanking you
codeperl
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the driver on the classpath and load the JDBC class with Class.forName()
 
Mohammad Ashrafuddin Ferdousi
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak Bala wrote:Put the driver on the classpath and load the JDBC class with Class.forName()

Thank you for your response. I think, already do it as i written down the code. can anyone help?
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have the Class.forName and DriverManager.getConnection in the wrong order - the Class.forName should come first.

Also, please use the code tag when posting source code - makes the source much easier to read. I added the tags for you this time.
 
Mohammad Ashrafuddin Ferdousi
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter Johnson wrote:You have the Class.forName and DriverManager.getConnection in the wrong order - the Class.forName should come first.

Also, please use the code tag when posting source code - makes the source much easier to read. I added the tags for you this time.

Thanks for your support, sir. Ok, i will do as you say.

Anyway, At last i found the solution by setting the classpath using eclipse ide. Actually i have to set the *.jar file using eclipse ide. That make my problem solved.

Thank you all for helping me. Have a nice day.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic