• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySql connection issue

 
kittu karan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34851
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kiran,
Is the mysql driver in your runtime classpath?
 
kittu karan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I don't have.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Download it from the MySQL website. Just search google for: mysql java connector.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kiran peruka:
No, I don't have.


then you should have.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic