Quote:
Originally Posted by mairaj
import java.sql.Connection;
import java.sql.DriverManager;
/**
*
* @author mairaj 
*/
public class DB {
static Connection con =null;
public static Connection getCon(){
try{
Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection("jdbc:mysql:\\localho st:3306\test","root","root") ;
}
catch(Exception e){}
return con;
}
}
|
Hi, miraj
You can try this code below
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase?","root","root");
Statement st=conn.createStatement();
// your code goes here...
//close try block
conn.close();
}catch(Exception e){
System.out.println("error"+e);
}
//3306 is default portnumber of mysql
//mydatabase is databasename in mysql
//root is username
//root is password
It will work 100%
Try it..
All the best..