• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

MySql connection issue

 
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.
 
author & internet detective
Posts: 40286
819
Eclipse IDE VI Editor Java
  • 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.
 
author
Posts: 4229
33
jQuery Eclipse IDE Java
 
Ranch Hand
Posts: 1325
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.
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic