Create static connection using MySQL server
Select your project in figure
Step: 1
Step: 2
Your Project Right Click and choose New option
Now Click Java Class...
Choose class name
example: dbconnnection
and Last click to finish
Write Code in java create connection
import java.sql.*; //import sql packages
public class dbconnection
{
private static Connection conn;
static
{
try
{
//Connection Driver Name
Class.forName("com.mysql.jdbc.Driver");
//Connection url("jdbc:mysql://localhost:3306/your database name","your user name","Your password");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/postoffice","root","");
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static Connection getConnection()
{
return conn;
}
}
Example
postoffice is my database name
and root my user name
and mypassword null




No comments:
Post a Comment