Author
MySql connection issue
kittu karan
Ranch Hand
Joined: Mar 09, 2008
Posts: 63
posted Mar 26, 2008 00:26:00
0
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: 26201
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
posted Mar 27, 2008 05:53:00
0
No, I don't have.
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
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: 1318
Originally posted by kiran peruka: No, I don't have.
then you should have.
Saifuddin..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
subject: MySql connection issue