This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes cant connect to mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "cant connect to mysql " Watch "cant connect to mysql " New topic
Author

cant connect to mysql

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 688

i have mysql installed on my machine and also i have set it up in my ide which is netbeans i have trying to perform simple databse operation
like follows
now my problem is

thanks for reading this

and one more thing my (mysql ) is runnng fine there is no problem in mysql

The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38100
    
  22
I presume that "MySQL is running" means you can run it from the command line.
How are you adding those drivers to the classpath? Always set the classpath locally, not as a system variable.
How are you passing the password?
Is jdbcodbc the right sort of Driver? Have you been through the MySQL handbook, which has a chapter in about connecting from Java™? Try § 20.3.
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 688

Campbell Ritchie wrote:I presume that "MySQL is running" means you can run it from the command line.
How are you adding those drivers to the classpath? Always set the classpath locally, not as a system variable.
How are you passing the password?
Is jdbcodbc the right sort of Driver? Have you been through the MySQL handbook, which has a chapter in about connecting from Java™? Try § 20.3.

no campbell this is not the code for the mysql this code is for connecting to the microsoft sql server with jdbcodbc driver
i m asking what should be the path means driver path in this code for connecting to mysql server
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38100
    
  22
Aren't the details in the MySQL documentation I mentioned earlier? You have to download a .jar with the connector in, and add it to your classpath. Don't set the classpath permanently.

And you are confusing me, asking about MySQL and showing SQL Server driver names.
Vishal Trivedi
Ranch Hand

Joined: Sep 05, 2011
Posts: 57
I use to have following line for my examples
Driver Instance
Class.forName("com.mysql.jdbc.Driver").newInstance();

getting connection
("jdbc:mysql://localhost/ databaseName", "UserName", "Password")


these features are however vendor specific. I had MySQLConnector
Downloaded it from the MySQL website

And besides there is plenty on the web about it.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38100
    
  22
Vishal Trivedi, thank you. That looks correct. Only, don't display a password, otherwise malicious code or naughty people may be able to read it and use it to harm you.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: cant connect to mysql
 
Similar Threads
exception while running my first jdbc code
using database connection in jframes
cant connect after disconnected from ftp server
com.microsoft.sqlserver.jdbc.SQLServerException is troubling me can any help please
problem with gui