MY SQL Data Base Connection



/*
      Author:ZT

      Date : Sep 6,2017

we asume that we have created DataBase  student and table st  where fields id as int  & fname as String
using Mysql DataBase





*/

import java.sql.*; 

 
class MysqlCon{ 

	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
  	 static final String DB_URL = "jdbc:mysql://localhost:3306";
	// static final String DB_URL = "jdbc:mysql://localhost/EMP";
   //  Database credentials
   	static final String USER = "root";
   	static final String PASS = "Dubai@2000";
   private static final String DB_CONNECTION = "jdbc:mysql://localhost:3306";





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

	Connection con1,con= null;
   	Statement stmt,stmt1= null;  
	try{  
	Class.forName(JDBC_DRIVER);  
	 con=DriverManager.getConnection(DB_URL,USER,PASS);
	// con1=DriverManager.getConnection(DB_URL,USER,PASS);
  
	//here sonoo is database name, root is username and password  
	stmt=con.createStatement();
	
	 // stmt1=con1.createStatement();
	   stmt.executeUpdate("insert into student.st(id,fname)values(710,'Sulyman Dawwod')") ;
  	
	ResultSet rs=stmt.executeQuery("select * from student.st");

  
	while(rs.next())  
		System.out.println(rs.getInt("id")+"  "+rs.getString("fname"));  
		 // con.close();
		}
		
		catch(Exception e){
		
	 	System.out.println(e);
		}  
	} 
	 

} // end of class