Monday, September 15, 2014

Eclipse SQL Connection on Ubuntu

Step 1: Intall JDK-JRE on Root
Step 2: Instell Eclipse
Step 3:

import java.sql.*;
public class Demo{

    public static void main(String[] args) {
        try{
           
            Class.forName("com.mysql.jdbc.driver");
        }catch(ClassNotFoundException e){
            System.out.println(e.getMessage());
        }
       
        try{
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/vish","root","vishal123");
            Statement st = con.createStatement();
            ResultSet rs=st.executeQuery("select * from emp");
            while(rs.next())
            {
                int emp_id = rs.getInt("EMPID");
                String emp_name=rs.getString("EMPNAME");
                String emp_dept=rs.getString("EMPDEPT");
                System.out.println("\nEMP ID= "+emp_id+"\nEMP Name= "+emp_name+"\nEMP Department= "+emp_dept);
               
            }
            st.close();
            con.close();
        }
        catch(SQLException e)
        {
            System.out.println(e.getMessage());
           
        }
    }

}

execute this code, you will gate error.
Step 4: https://www.youtube.com/watch?v=Ulp9mOuDWac

No comments:

Post a Comment