Data Base Connectivity MySql to java Program-example - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
Data Base Connectivity MySql to java Program-example

Data Base Connectivity MySql to java Program-example

package connection;
import java.sql.*;

public class MysqlCon {
public static void main(String[]args)
{


try {
      Class.forName("com.mysql.jdbc.Driver");
      System.out.println("Driver loaded");
   
    Connection  con=DriverManager.getConnection(
      "jdbc:mysql://localhost:3307/prince","root","root");
     System.out.println("Connection etaiblish");
 
 
     Statement stmt=con.createStatement();
     ResultSet rs=stmt.executeQuery("select * FROM emp");
 
     while(rs.next())
     System.out.println(rs.getString(1)+"  "+rs.getInt(2)+""+rs.getString(3)+""+rs.getInt(4)+"");
     con.close();
 
   }
catch(ClassNotFoundException e) {
System.out.println("exception="+e.getMessage());

}



catch(SQLException e) {
System.out.println("exception="+e.getMessage());
}
}



}

About EasyToCode

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.