954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

connecting java to mysql database

i am trying to connect java program to mysql databse. bascically i am aphp programmer. now i want to lear j2ee so i was trying to connect to mysql database.i am getting the error as not able to load the drive
thi sis my code
import java.sql.*;

public class tc { static public void main (String args[])
{
Connection con = null;

try
{
Class.forName("MySql ODBC 3.51 Driver");
}

catch (Exception e)
{
System.err.println("Unable to load driver.");
e.printStackTrace();
return;
}

try {

con = DriverManager.getConnection(
"jdbc:mysql://localhost/login?user=nagaraja sastry&password=g86iyug");

System.out.println("Connection successful!");
System.out.println("I AM IN THE TEST DATABASE!"); }

catch(SQLException e)
{ e.printStackTrace(); }

finally { if (con != null )
{
try { con.close();
System.out.println("I HAVE CLOSED THE CONNECTION TO THE DATABASE!");
}
catch (SQLException e )
{ e.printStackTrace(); }
} //if
} //finally
} //main
} //tcdb
anybody pls help me
tahnks

aarya
Junior Poster
139 posts since Sep 2005
Reputation Points: 11
Solved Threads: 0
 
Class.forName("MySql ODBC 3.51 Driver");


and you wonder why it won't load?
Go read the documentation...

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You