import java.sql.*;
public class MySqlConnect {
public static void main (String[] args)
{
Connection connection = null;
try
{
String userName = "root";
String password = "bunty";
String url = "jdbc:mysql://localhost:3306/systdb";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
connection = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Connection to database server cannot be establish");
}
finally
{
if (connection != null)
{
try
{
connection.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { System.out.println ("These connection errors can be ignored."); }
}
}
}
}
Wednesday, October 24, 2007
How do you connect to a MySql Database using JDBC?
Subscribe to:
Post Comments (Atom)


0 comments:
Post a Comment