This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes MySql connection issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySql connection issue" Watch "MySql connection issue" New topic
Author

MySql connection issue

kittu karan
Ranch Hand

Joined: Mar 09, 2008
Posts: 63
Hi,
I wrote below code
import java.io.*;
import java.sql.*;
public class JdbcConnection {
public static void main (String[] args)
{
try{
String userName = "root";
String password = "admin";
//String url = "jdbc:mysql://localhost:3306/test";
String url="jdbc:kiran";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection (url,userName ,password );
System.out.println ("Database connection established");
}catch (Exception e)
{
e.printStackTrace();
System.err.println ("Cannot connect to database server");
}
}
}

I created DSN name as kiran using MySQL ODBC 3.51 Driver.
No compilation error occuring but runtime error is occuring like

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
other exception regarding url and classloader
whether I have to set any jar files.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Kiran,
Is the mysql driver in your runtime classpath?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
kittu karan
Ranch Hand

Joined: Mar 09, 2008
Posts: 63
No, I don't have.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3700
    
    5

Download it from the MySQL website. Just search google for: mysql java connector.


My Blog: Down Home Country Coding with Scott Selikoff
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Originally posted by kiran peruka:
No, I don't have.


then you should have.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MySql connection issue
 
Similar Threads
connecting to mysql, with java, on a mac
Problem with com.mysql.jdbc.Driver driver
problem with MySQL driver
problem with MySQL driver
Singleton Connection Class