aspose file tools*
The moose likes JDBC and the fly likes JDBC, mysql connector/j, face a problem to connect mysql 5.1 and JSE. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC, mysql connector/j, face a problem to connect mysql 5.1 and JSE." Watch "JDBC, mysql connector/j, face a problem to connect mysql 5.1 and JSE." New topic
Author

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

Mohammad Ashrafuddin Ferdousi
Ranch Hand

Joined: Jan 14, 2010
Posts: 111
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

Joined: Feb 24, 2006
Posts: 6657
    
    5

Put the driver on the classpath and load the JDBC class with Class.forName()


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Mohammad Ashrafuddin Ferdousi
Ranch Hand

Joined: Jan 14, 2010
Posts: 111
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

Joined: May 14, 2008
Posts: 5772
    
    7

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.


JBoss In Action
Mohammad Ashrafuddin Ferdousi
Ranch Hand

Joined: Jan 14, 2010
Posts: 111
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC, mysql connector/j, face a problem to connect mysql 5.1 and JSE.
 
Similar Threads
Help - - - ClassNotFoundException: com.mysql.jdbc.Driver
MySql connectivity problem?
WAMP/Java/MysqlConnector Issue
MySQL DataBase
not able to connect to the database