First install the Mysql/Java connector in ur pc or add the dll files needed found here
MySql/J connector
final static String userName = "root";
final static String password = "";
final static String url = "jdbc:mysql://192.168.60.93/java";// String url = "jdbc:mySubprotocol:myDataSource"; ?
Statement stmt;
Connection conn=null;
final static String password = "";
final static String url = "jdbc:mysql://192.168.60.93/java";// String url = "jdbc:mySubprotocol:myDataSource"; ?
Statement stmt;
Connection conn=null;
for creating connection use the following codes which is easy:
public void Create_conn()
{
try
{
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
errmsg ="Cannot connect to database server"+e.getMessage();
JOptionPane.showMessageDialog(null,errmsg, "Error msg", JOptionPane.ERROR_MESSAGE);
}
}
{
try
{
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
errmsg ="Cannot connect to database server"+e.getMessage();
JOptionPane.showMessageDialog(null,errmsg, "Error msg", JOptionPane.ERROR_MESSAGE);
}
}
0 comments:
Post a Comment