Lara

JDBC

Saturday(31-12-2016)

import java.sql.*;

class Manager21

{

            public static void main(String[] args)

            {

                        String sql = "CREATE OR REPLACE PROCEDURE P1 " +

                                                             "AS BEGIN " +

                                                             "INSERT INTO EMPLOYEE VALUES(1, 'ABC', 22);" +

                                                             "INSERT INTO EMPLOYEE VALUES(2, 'XYZ', 24);" +

                                                             "INSERT INTO EMPLOYEE VALUES(3, 'RAMU', 25);" +

                                                             "INSERT INTO EMPLOYEE VALUES(4, 'BHANU', 28);" +

                                                             "END;";

                        Connection con = null;

                        Statement stmt = null;

                        try

                        {

                                    con = Util.getConnection();

                                    stmt = con.createStatement();

                                    stmt.execute(sql);

                                    System.out.println("done");

                        }

                        catch (SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    Util.closeResources(null, stmt, con);

                        }

            }

}

import java.sql.*;

class Manager22

{

            public static void main(String[] args)

            {

                        Connection con = null;

                        CallableStatement cstmt = null;

                        try

                        {

                                    con = Util.getConnection();

                                    cstmt = con.prepareCall("{call p1}");

                                    cstmt.execute();

                        }

                        catch (SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    Util.closeResources(null, cstmt, con);

                        }

                        System.out.println("done");

            }

}

import java.sql.*;

class Manager23

{

            public static void main(String[] args)

            {

                        String sql = "create or replace procedure p2 as begin " +

                                                             "insert into employee values(5, 'vijay', 33);" +

                                                             "update employee set name='manu' where id = 2;" +

                                                             "delete from employee where id = 3;" +

                                                             "insert into tab1 values(15, 'vijay', 43);" +

                                                             "end;";

                        Connection con = null;

                        Statement stmt = null;

                        try

                        {

                                    con = Util.getConnection();

                                    stmt = con.createStatement();

                                    stmt.execute(sql);

                        }

                        catch (SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    Util.closeResources(null, stmt, con);

                        }

                        System.out.println("done");

            }

}

import java.sql.*;

class Manager24

{

            public static void main(String[] args)

            {

                        Connection con = null;

                        CallableStatement cstmt = null;

                        try

                        {

                                    con = Util.getConnection();

                                    cstmt = con.prepareCall("{call p2}");

                                    cstmt.execute();

                        }

                        catch (SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    Util.closeResources(null, cstmt, con);

                        }

                        System.out.println("done");

            }

}

import java.sql.*;

class Manager25

{

            public static void main(String[] args)

            {

                        String sql =

"create or replace procedure p3(sno number, name varchar2, age number) " +

                                                     "as begin " +

                                                             "insert into employee values(sno, name, age);" +

                                                             "insert into tab1 values(sno, name, age);" +

                                                             "end;";

                        Connection con = null;

                        Statement stmt = null;

                        try

                        {

                                    con = Util.getConnection();

                                    stmt = con.createStatement();

                                    stmt.execute(sql);

                        }

                        catch (SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    Util.closeResources(null, stmt, con);

                        }

                        System.out.println("done");

            }

}

import java.sql.*;

class Manager26

{

            public static void main(String[] args)

            {

                        Connection con = null;

                        CallableStatement cstmt = null;

                        try

                        {

                                    con = Util.getConnection();

                                    cstmt = con.prepareCall("{call p3(20, 'mohan', 33)}");

                                    cstmt.execute();

                        }

                        catch (SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    Util.closeResources(null, cstmt, con);

                        }

                        System.out.println("done");

            }

}

import java.sql.*;

class Manager27

{

            public static void main(String[] args)

            {

                        Connection con = null;

                        CallableStatement cstmt = null;

                        try

                        {

                                    con = Util.getConnection();

                                    cstmt = con.prepareCall("{call p3(?, ?, ?)}");

                                    cstmt.setInt(1, 25);

                                    cstmt.setString(2, "MURALI");

                                    cstmt.setInt(3, 50);

                                    cstmt.execute();

 

                                    cstmt.setInt(1, 26);

                                    cstmt.setString(2, "Manohar");

                                    cstmt.setInt(3, 51);

                                    cstmt.execute();

 

                        }

                        catch (SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    Util.closeResources(null, cstmt, con);

                        }

                        System.out.println("done");

            }

}

 Saturday(07-01-2017)

package com.lara;

 

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

 

public class Manager1

{

            public static void main(String[] args) throws Exception

            {

                        Class.forName("oracle.jdbc.driver.OracleDriver");                        

                        Connection con =

                                                DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE",

                                                                                                                            "system", "great123");

                        Statement stmt = con.createStatement();

                        ResultSet rs = stmt.executeQuery("select * from employee");

                        while(rs.next())

                        {

                                    System.out.print(rs.getString(1));

                                    System.out.print(", " + rs.getString(2));

                                    System.out.println(", " + rs.getString(3));

                        }

                       

                       

                       

                       

                       

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager2

{

            public static void main(String[] args)

            {

                        String sql = "select * from employee";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement();

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    while(rs.next())

                                    {

                                                System.out.print(rs.getString(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(rs.getString(3));

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.io.FileReader;

import java.io.IOException;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.util.Properties;

 

public class DbUtil

{

            private static final String driverClassName;

            private static final String url;

            private static final String username;

            private static final String password;

           

            static

            {

                        Properties pr = new Properties();

                        try(FileReader fin = new FileReader("db-constants.properties"))

                        {

                                    pr.load(fin);

                        }

                        catch(IOException ex)

                        {

                                    ex.printStackTrace();

                        }

                        driverClassName = pr.getProperty("driverClassName");

                        url = pr.getProperty("url");

                        username = pr.getProperty("username");

                        password = pr.getProperty("password");

            }

            static

            {

                        try

                        {

                                    Class.forName(driverClassName);

                        }

                        catch(ClassNotFoundException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

            public static Connection getConnection() throws SQLException

            {

                        return DriverManager.getConnection(url, username, password);

            }

}

 

 

package com.lara;

 

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager3

{

            public static void main(String[] args)

            {

                        String sql = "create or replace procedure p4(arg1 number, arg2 out varchar2) ";

                        sql += "as begin ";

                        sql += "select name into arg2 from employee where id = arg1;";

                        sql += "end;";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement())

                        {

                                    stmt.execute(sql);

                                    System.out.println("done");

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                       

                       

                       

            }

}

package com.lara;

 

import java.sql.CallableStatement;

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Types;

 

public class Manager4

{

            public static void main(String[] args)

            {

                        String sql = "{call p4(?, ?)}";

                        try(Connection con = DbUtil.getConnection();

                                    CallableStatement cstmt = con.prepareCall(sql))

                        {

                                    cstmt.setInt(1, 26);

                                    cstmt.registerOutParameter(2, Types.VARCHAR);

                                    cstmt.execute();

                                    String name = cstmt.getString(2);

                                    System.out.println(name);

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.CallableStatement;

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Types;

 

public class Manager5

{

            public static void main(String[] args)

            {

                        String sql = "{call p4(25, ?)}";

                        try(Connection con = DbUtil.getConnection();

                                    CallableStatement cstmt = con.prepareCall(sql))

                        {

                                    cstmt.registerOutParameter(1, Types.VARCHAR);

                                    cstmt.execute();

                                    String name = cstmt.getString(1);

                                    System.out.println(name);

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager6

{

            public static void main(String[] args)

            {

                        StringBuffer sql = new StringBuffer();

                        sql.append("create or replace procedure p5(arg1 in out number) ");

                        sql.append("as begin ");

                        sql.append("select age into arg1 from employee where id = arg1;");

                        sql.append("end;");

                       

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement())

                        {

                                    stmt.execute(sql.toString());

                                    System.out.println("done");

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.CallableStatement;

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Types;

 

public class Manager7

{

            public static void main(String[] args)

            {

                        String sql = "{ call p5(?) }";

                        try(Connection con = DbUtil.getConnection();

                                    CallableStatement cstmt = con.prepareCall(sql))

                        {

                                    cstmt.setInt(1, 25);

                                    cstmt.registerOutParameter(1, Types.INTEGER);

                                    cstmt.execute();

                                    int age = cstmt.getInt(1);

                                    System.out.println(age);

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

db-constants.properties

driverClassName=oracle.jdbc.driver.OracleDriver

url=jdbc:oracle:thin:@localhost:1521:XE

username=system

password=great123

 

 Sunday(08-01-2017)

package com.lara;

 

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager8

{

            public static void main(String[] args)

            {

                        StringBuffer sql = new StringBuffer();

                        sql.append("CREATE TABLE EMPLOYEE(ID NUMBER PRIMARY KEY, ");

                        sql.append("FIRST_NAME VARCHAR2(90), ");

                        sql.append("LAST_NAME VARCHAR2(90), ");

                        sql.append("AGE NUMBER, ");

                        sql.append("ROW_ID ROWID, ");

                        sql.append("PIC BLOB) ");                      

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement())

                        {

                                    stmt.execute(sql.toString());

                                    System.out.println("done");

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager9

{

            public static void main(String[] args)

            {

                        StringBuffer sb1 = new StringBuffer();

                        sb1.append("INSERT INTO EMPLOYEE(ID, FIRST_NAME, LAST_NAME, AGE) ");

                        sb1.append("VALUES(1, 'RAMU', 'B', 34) ");

 

                        StringBuffer sb2 = new StringBuffer();

                        sb2.append("INSERT INTO EMPLOYEE(ID, FIRST_NAME, LAST_NAME, AGE) ");

                        sb2.append("VALUES(2, 'manu', 'B', 24) ");

           

                        StringBuffer sb3 = new StringBuffer();

                        sb3.append("INSERT INTO EMPLOYEE(ID, FIRST_NAME, LAST_NAME, AGE) ");

                        sb3.append("VALUES(3, 'venu', 'c', 44) ");

           

                        StringBuffer sb4 = new StringBuffer();

                        sb4.append("INSERT INTO EMPLOYEE(ID, FIRST_NAME, LAST_NAME, AGE) ");

                        sb4.append("VALUES(4, 'vishal', 'e', 46) ");

           

                        StringBuffer sb5 = new StringBuffer();

                        sb5.append("INSERT INTO EMPLOYEE(ID, FIRST_NAME, LAST_NAME, AGE) ");

                        sb5.append("VALUES(5, 'rupa', 't', 26) ");

           

           

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement())

                        {

                                    stmt.executeUpdate(sb1.toString());

                                    stmt.executeUpdate(sb2.toString());

                                    stmt.executeUpdate(sb3.toString());

                                    stmt.executeUpdate(sb4.toString());

                                    stmt.executeUpdate(sb5.toString());

                                    System.out.println("done");

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

           

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager10

{

            public static void main(String[] args)

            {

                        String sql = "SELECT ID, FIRST_NAME, LAST_NAME, AGE FROM EMPLOYEE";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

                                                                                                                                                 ResultSet.CONCUR_UPDATABLE);

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    System.out.println("in the forward direction");

                                    while(rs.next())

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

                                    System.out.println("in the reverse direction");

                                    while(rs.previous())

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

                                    System.out.println("in the forward direction");

                                    while(rs.next())

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }                                  

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager11

{

            public static void main(String[] args)

            {

                        String sql = "SELECT ID, FIRST_NAME, LAST_NAME, AGE FROM EMPLOYEE";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

                                                                                                                                                 ResultSet.CONCUR_UPDATABLE);

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    System.out.println("in the reverse direction");

                                    rs.afterLast();

                                    while(rs.previous())

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

                                    System.out.println("in the reverse direction");

                                    rs.afterLast();

                                    while(rs.previous())

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }                                  

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager12

{

            public static void main(String[] args)

            {

                        String sql = "SELECT ID, FIRST_NAME, LAST_NAME, AGE FROM EMPLOYEE";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

                                                                                                                                                 ResultSet.CONCUR_UPDATABLE);

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    System.out.println("in the forward direction");

                                    while(rs.next())

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

                                    rs.beforeFirst();

                                    System.out.println("in the forward direction");

                                    while(rs.next())

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager13

{

            public static void main(String[] args)

            {

                        String sql = "SELECT ID, FIRST_NAME, LAST_NAME, AGE FROM EMPLOYEE";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

                                                                                                                                                 ResultSet.CONCUR_UPDATABLE);

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    System.out.println("read 3rd record");

                                    if(rs.absolute(3))

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager14

{

            public static void main(String[] args)

            {

                        String sql = "SELECT ID, FIRST_NAME, LAST_NAME, AGE FROM EMPLOYEE";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

                                                                                                                                                 ResultSet.CONCUR_UPDATABLE);

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    System.out.println("read 1st record");

                                    if(rs.absolute(-5))

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager15

{

            public static void main(String[] args)

            {

                        String sql = "SELECT ID, FIRST_NAME, LAST_NAME, AGE FROM EMPLOYEE";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

                                                                                                                                                 ResultSet.CONCUR_UPDATABLE);

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    System.out.println("read 2nd record");

                                    if(rs.absolute(2))

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

                                    System.out.println("read 4th record");

                                    if(rs.relative(2))

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

 

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class Manager16

{

            public static void main(String[] args)

            {

                        String sql = "SELECT ID, FIRST_NAME, LAST_NAME, AGE FROM EMPLOYEE";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

                                                                                                                                                 ResultSet.CONCUR_UPDATABLE);

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    System.out.println("read 5th record");

                                    if(rs.absolute(5))

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

                                    System.out.println("read 1st record");

                                    if(rs.relative(-4))

                                    {

                                                System.out.print(rs.getInt(1));

                                                System.out.print(", " + rs.getString(2));

                                                System.out.println(", " + rs.getString(3));

                                    }

 

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager17

{

            public static void main(String[] args)

            {

                        String sql = "SELECT ID, FIRST_NAME, LAST_NAME, AGE FROM EMPLOYEE";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

                                                                                                                                                 ResultSet.CONCUR_UPDATABLE);

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    if(rs.absolute(3))

                                    {

                                                rs.updateString("last_name", "test");

                                                rs.updateInt("age", 55);

                                                rs.updateRow();

                                    }

                                    System.out.println("done");

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager18

{

            public static void main(String[] args)

            {

                        String sql = "SELECT ID, FIRST_NAME, LAST_NAME, AGE FROM EMPLOYEE";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

                                                                                                                                                 ResultSet.CONCUR_UPDATABLE);

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    if(rs.absolute(4))

                                    {

                                                rs.deleteRow();

                                    }

                                    System.out.println("done");

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager19

{

            public static void main(String[] args)

            {

                        String sql = "SELECT ID, FIRST_NAME, LAST_NAME, AGE FROM EMPLOYEE";

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

                                                                                                                                                 ResultSet.CONCUR_UPDATABLE);

                                    ResultSet rs = stmt.executeQuery(sql))

                        {

                                    rs.moveToInsertRow();

                                    rs.updateInt("id", 6);

                                    rs.updateString("first_name", "bhnau");

                                    rs.updateString("last_name", "kiran");

                                    rs.updateInt("age", 22);

                                    rs.insertRow();

                                    System.out.println("done");

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara;

 

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.RowId;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager20

{

            public static void main(String[] args)

            {

                        String sql = "INSERT INTO EMPLOYEE(ID, FIRST_NAME, LAST_NAME, AGE) ";

                        sql += "VALUES(56, 'manohar', 'test', 25)";

                       

                        String updateSql = "UPDATE EMPLOYEE SET ROW_ID = ? WHERE ID = 29";

                       

                        ResultSet rs = null;

                        try(Connection con = DbUtil.getConnection();

                                    Statement stmt = con.createStatement();

                                    PreparedStatement pstmt = con.prepareStatement(updateSql))

                        {

                                    stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);

                                    rs = stmt.getGeneratedKeys();

                                    RowId rowId = null;

                                    if(rs.next())

                                    {

                                                rowId = rs.getRowId("ROWID");

                                                System.out.println(rowId);

                                    }

                                    pstmt.setRowId(1, rowId);

                                    pstmt.executeUpdate();

                                    System.out.println("done");

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    if(rs != null)

                                    {

                                                try

                                                {

                                                            rs.close();

                                                            rs = null;

                                                }

                                                catch(SQLException ex)

                                                {

                                                            ex.printStackTrace();

                                                }

                                    }

                        }

            }

}

 Sunday(15-01-2017)

package com.lara;

 

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.RowId;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager20

{

          public static void main(String[] args)

          {

                   String sql = "INSERT INTO EMPLOYEE(ID, FIRST_NAME, LAST_NAME, AGE) ";

                   sql += "VALUES(102, 'manohar', 'test', 25)";

                  

                   String updateSql = "UPDATE EMPLOYEE SET ROW_ID = ? WHERE ID = 102";

                  

                   ResultSet rs = null;

                   try(Connection con = DbUtil.getConnection();

                             Statement stmt = con.createStatement();

                             PreparedStatement pstmt = con.prepareStatement(updateSql))

                   {

                             stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);

                             rs = stmt.getGeneratedKeys();

                             String rowId = null;

                             if(rs.next())

                             {

                                      rowId = rs.getString(1);

                                      System.out.println(rowId);

                             }

                             pstmt.setString(1, rowId);

                             pstmt.executeUpdate();

                             System.out.println("done");

                   }

                   catch(SQLException ex)

                   {

                             ex.printStackTrace();

                   }

                   finally

                   {

                             if(rs != null)

                             {

                                      try

                                      {

                                                rs.close();

                                                rs = null;

                                      }

                                      catch(SQLException ex)

                                      {

                                                ex.printStackTrace();

                                      }

                             }

                   }

          }

}

package com.lara;

 

import java.io.BufferedInputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.SQLException;

 

public class Manager21

{

          public static void main(String[] args)

          {

                   String sql = "INSERT INTO EMPLOYEE(ID, PIC) VALUES(103, ?)";

                   File f1 = new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg");

                   byte[] bytes = new byte[(int) f1.length()];

                   try(Connection con = DbUtil.getConnection();

                             PreparedStatement pstmt = con.prepareStatement(sql);

                             FileInputStream fin = new FileInputStream(f1);

                             BufferedInputStream bin = new BufferedInputStream(fin))

                   {

                             bin.read(bytes);

                             pstmt.setObject(1, bytes);

                             pstmt.executeUpdate();

                             System.out.println("done");

                   }

                   catch(SQLException ex)

                   {

                             ex.printStackTrace();

                   }

                   catch(IOException ex)

                   {

                             ex.printStackTrace();

                   }

          }

}

package com.lara;

 

import java.io.BufferedOutputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.sql.Blob;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class Manager22

{

          public static void main(String[] args)

          {

                   String sql = "SELECT * FROM EMPLOYEE WHERE ID = 103";

                   try(Connection con = DbUtil.getConnection();

                             Statement stmt = con.createStatement();

                             ResultSet rs = stmt.executeQuery(sql);

                             FileOutputStream out = new FileOutputStream("test.jpg");

                             BufferedOutputStream bout = new BufferedOutputStream(out))

                   {

                             if(rs.next())

                             {

                                      Blob pic = rs.getBlob("PIC");

                                      byte[] bytes = pic.getBytes(1, (int) pic.length());

                                      bout.write(bytes);

                                      System.out.println("done");

                             }

                   }

                   catch(SQLException ex)

                   {

                             ex.printStackTrace();

                   }

                   catch(IOException ex)

                   {

                             ex.printStackTrace();

                   }

          }

}

 Saturday(21-01-2017)

A Simple Employee Management System in Core java, JDBC and Oracle

 

CREATE SEQUENCE GENDER_SEQ INCREMENT BY 1 START WITH 1;

CREATE TABLE GENDER(ID INT UNIQUE, NAME VARCHAR(90));

INSERT INTO GENDER VALUES(GENDER_SEQ.NEXTVAL, 'MALE');

INSERT INTO GENDER VALUES(GENDER_SEQ.NEXTVAL, 'FEMALE');

CREATE SEQUENCE SKILL_SEQ INCREMENT BY 1 START WITH 1;

CREATE TABLE SKILL(ID INT UNIQUE, NAME VARCHAR(90));

INSERT INTO SKILL VALUES(SKILL_SEQ.NEXTVAL, 'C');

INSERT INTO SKILL VALUES(SKILL_SEQ.NEXTVAL, 'C++');

INSERT INTO SKILL VALUES(SKILL_SEQ.NEXTVAL, 'JAVA');

INSERT INTO SKILL VALUES(SKILL_SEQ.NEXTVAL, 'ORACLE');

CREATE SEQUENCE EDUCATION_SEQ INCREMENT BY 1 START WITH 1;

CREATE TABLE EDUCATION(ID INT UNIQUE, NAME VARCHAR(90));

INSERT INTO EDUCATION VALUES(EDUCATION_SEQ.NEXTVAL, 'B.TECH');

INSERT INTO EDUCATION VALUES(EDUCATION_SEQ.NEXTVAL, 'M.TECH');

INSERT INTO EDUCATION VALUES(EDUCATION_SEQ.NEXTVAL, 'M.C.A');

INSERT INTO EDUCATION VALUES(EDUCATION_SEQ.NEXTVAL, 'M.B.A');

INSERT INTO EDUCATION VALUES(EDUCATION_SEQ.NEXTVAL, 'B.C.A');

CREATE SEQUENCE PROJECT_SEQ INCREMENT BY 1 START WITH 1;

CREATE TABLE PROJECT(ID INT UNIQUE, NAME VARCHAR(90), DURATION INT, START_DATE DATE);

INSERT INTO PROJECT VALUES(PROJECT_SEQ.NEXTVAL, 'CITI', 120,

                                                TO_DATE('01-09-2014', 'DD-MM-YYYY'));

INSERT INTO PROJECT VALUES(PROJECT_SEQ.NEXTVAL, 'HDFC', 150,

                                                TO_DATE('10-09-2014', 'DD-MM-YYYY'));

INSERT INTO PROJECT VALUES(PROJECT_SEQ.NEXTVAL, 'AXIS', 180,

                                                TO_DATE('15-09-2014', 'DD-MM-YYYY'));

CREATE SEQUENCE EMPLOYEE_SEQ INCREMENT BY 1 START WITH 1;

CREATE TABLE EMPLOYEE(ID INT UNIQUE,

                              FIRST_NAME VARCHAR(90),

                              LAST_NAME VARCHAR(90),

                              DATE_BIRTH TIMESTAMP,

                              GENDER_ID INT,

                              LATEST_EDUCATION_ID INT,

                              JOINING_DATE DATE,

                              PROJECT_ID INT,

                              USERNAME VARCHAR(90),

                              PASSWORD VARCHAR(90),

                              CONSTRAINT EMP_FK1 FOREIGN KEY (GENDER_ID) REFERENCES GENDER(ID),

                              CONSTRAINT EMP_FK2 FOREIGN KEY (LATEST_EDUCATION_ID) REFERENCES EDUCATION(ID),

                              CONSTRAINT EMP_FK3 FOREIGN KEY (PROJECT_ID) REFERENCES PROJECT(ID))

CREATE SEQUENCE ADDRESS_SEQ INCREMENT BY 1 START WITH 1;

CREATE TABLE ADDRESS(ID INT UNIQUE,

                             HOUSE_NO VARCHAR(90),

                             STREET_NAME VARCHAR(90),

                             CITY VARCHAR(90),

                             STATE VARCHAR(90),

                             EMPLOYEE_ID INT UNIQUE,

                             CONSTRAINT ADDRESS_FK1 FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE(ID))

CREATE TABLE EMPLOYEE_SKILL(EMPLOYEE_ID INT,

                                        SKILL_ID INT,

                                        CONSTRAINT ES_FK1 FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE(ID),

                                        CONSTRAINT ES_FK2 FOREIGN KEY (SKILL_ID) REFERENCES SKILL(ID))

 

 

package com.lara.entity;

public class Address

{

            private String houseNo;

            private String streetName;

            private String city;

            private String state;

            private int empId;

            //setters and getters

}

package com.lara.entity;

public class Education

{

            private int id;

            private String name;

            //setters and getters

}

package com.lara.entity;

public class Gender

{

            private Integer id;

            private String name;

            //setters and getters

}

package com.lara.entity;

public class Project

{

            private int id;

            private String name;

            //setters and getters

}

package com.lara.entity;

public class Skill

{

            private int id;

            private String name;

            //setters and getters

}

package com.lara.entity;

public class Employee

{

            private String firstName;

            private String lastName;

            private String dob;

            private int genderId;

            private int educationId;

            private int projectId;

            private int[] skillIds;

            private String doj;

            private Address address;

            private String username;

            private String password;

            //setters and getters

}

package com.lara.db.util;

import java.io.FileReader;

import java.io.IOException;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.Properties;

public class DbUtil

{

            private static final String driverClass;

            private static final String url;

            private static final String username;

            private static final String password;

            static

            {

                        Properties pr = new Properties();

                        FileReader in = null;

                        try

                        {

                                    in = new FileReader("constants.properties");

                                    pr.load(in);

                        }

                        catch(IOException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    try

                                    {

                                                if(in != null)

                                                {

                                                            in.close();

                                                            in = null;

                                                }

                                    }

                                    catch(IOException ex)

                                    {

                                                ex.printStackTrace();

                                    }

                        }

                        driverClass = pr.getProperty("driverClass");

                        url = pr.getProperty("url");

                        username = pr.getProperty("username");

                        password = pr.getProperty("password");

            }

            static

            {

                        try

                        {

                                    Class.forName(driverClass);

                        }

                        catch(ClassNotFoundException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

            public static Connection getConnection()

            throws SQLException

            {

                        return DriverManager.getConnection(url, username, password);

            }

            public static void closeAll(ResultSet rs, Statement stmt, Connection con)

            {

                        try

                        {

                                    if(rs != null)

                                    {

                                                rs.close();

                                                rs = null;

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        try

                        {

                                    if(stmt != null)

                                    {

                                                stmt.close();

                                                stmt = null;

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        try

                        {

                                    if(con != null)

                                    {

                                                con.close();

                                                con = null;

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

            }

}

package com.lara.db.dao;

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Statement;

import com.lara.db.util.DbUtil;

import com.lara.entity.Address;

public class AddressDAO

{

            public static int insertAddress(Address add)

            {

                        StringBuffer sql = new StringBuffer();

                        sql.append("insert into address(id, house_no,");

                        sql.append("street_name, city, state, employee_id) ");

                        sql.append("values(address_seq.nextval, ");

                        sql.append("'" + add.getHouseNo() + "',");

                        sql.append("'" + add.getStreetName() + "',");

                        sql.append("'" + add.getCity() + "',");

                        sql.append("'" + add.getState() + "',");

                        sql.append(add.getEmpId() + ")");

                        int status = 0;

                        Connection con = null;

                        Statement stmt = null;                 

                        try

                        {

                                    con = DbUtil.getConnection();

                                    stmt = con.createStatement();

                                    status = stmt.executeUpdate(sql.toString());

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    DbUtil.closeAll(null, stmt, con);

                        }

                        return status;

            }

}

package com.lara.db.dao;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;

import com.lara.db.util.DbUtil;

import com.lara.entity.Education;;

public class EducationDAO

{

            public static List<Education> readAllEducations()

            {

                        List<Education> educations = new ArrayList<>();

                        Connection con = null;

                        Statement stmt = null;

                        ResultSet rs = null;

                        try

                        {

                                    con = DbUtil.getConnection();

                                    stmt = con.createStatement();

                                    rs = stmt.executeQuery("select id, name from education");

                                    Education education = null;

                                    while(rs.next())

                                    {

                                                education = new Education();

                                                education.setId(rs.getInt("id"));

                                                education.setName(rs.getString("name"));

                                                educations.add(education);

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    DbUtil.closeAll(rs, stmt, con);

                        }

                        return educations;

            }

}

package com.lara.db.dao;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import com.lara.db.util.DbUtil;

import com.lara.entity.Employee;

public class EmployeeDAO

{

            public static int insertEmployee(Employee emp)

            {

                        StringBuffer sql = new StringBuffer();

                        sql.append("insert into employee(id, first_name, ");

                        sql.append("last_name, date_birth, gender_id, ");

                        sql.append("latest_education_id, joining_date, ");

                        sql.append("project_id, username, password) ");

                        sql.append("values(employee_seq.nextval, ");

                        sql.append("'" + emp.getFirstName() + "', ");

                        sql.append("'" + emp.getLastName() + "', ");

                        sql.append("to_timestamp('" + emp.getDob() + "', 'DD-MON-YYYY'),");// HH24:MI:SS'), ");

                        sql.append(emp.getGenderId() + ", ");

                        sql.append(emp.getEducationId() + ", ");

                        sql.append("to_date('" + emp.getDoj() + "', 'DD-MON-YYYY'), ");

                        sql.append(emp.getProjectId() + ", ");

                        sql.append("'" + emp.getUsername() + "', ");

                        sql.append("'" + emp.getPassword() + "')");

                        String sqlSkills = "insert into employee_skill(employee_id, skill_id) values(?, ?)";

                        String sqlEmpSelect = "select max(id) as id from employee";

                        Connection con = null;

                        Statement stmt = null;

                        PreparedStatement pstmt = null;

                        ResultSet rs = null;

                        int status = 0;

                        int empId = 0;

                        try

                        {

                                    con = DbUtil.getConnection();

                                    stmt = con.createStatement();

                                    status = stmt.executeUpdate(sql.toString());

                                    rs = stmt.executeQuery(sqlEmpSelect);

                                    if(rs.next())

                                    {

                                                empId = rs.getInt("id");

                                    }

                                    emp.getAddress().setEmpId(empId);

                                    pstmt = con.prepareStatement(sqlSkills);

                                    for(int skillId : emp.getSkillIds())

                                    {

                                                pstmt.setInt(1, empId);

                                                pstmt.setInt(2, skillId);

                                                pstmt.executeUpdate();

                                    }

                                    AddressDAO.insertAddress(emp.getAddress());

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();                               

                        }

                        finally

                        {

                                    DbUtil.closeAll(rs, stmt, con);

                                    DbUtil.closeAll(null, pstmt, null);

                        }

                        return status;

            }

}

package com.lara.db.dao;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;

import com.lara.db.util.DbUtil;

import com.lara.entity.Gender;

public class GenderDAO

{

            public static List<Gender> readAllGenders()

            {

                        List<Gender> genders = new ArrayList<>();

                        Connection con = null;

                        Statement stmt = null;

                        ResultSet rs = null;

                        try

                        {

                                    con = DbUtil.getConnection();

                                    stmt = con.createStatement();

                                    rs = stmt.executeQuery("select id, name from gender");

                                    Gender gender = null;

                                    while(rs.next())

                                    {

                                                gender = new Gender();

                                                gender.setId(rs.getInt("id"));

                                                gender.setName(rs.getString("name"));

                                                genders.add(gender);

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    DbUtil.closeAll(rs, stmt, con);

                        }

                        return genders;

            }

}

package com.lara.db.dao;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;

import com.lara.db.util.DbUtil;

import com.lara.entity.Project;

public class ProjectDAO

{

            public static List<Project> readAllProjects()

            {

                        List<Project> projects = new ArrayList<>();

                        Connection con = null;

                        Statement stmt = null;

                        ResultSet rs = null;

                        try

                        {

                                    con = DbUtil.getConnection();

                                    stmt = con.createStatement();

                                    rs = stmt.executeQuery("select id, name from project");

                                    Project project = null;

                                    while(rs.next())

                                    {

                                                project = new Project();

                                                project.setId(rs.getInt("id"));

                                                project.setName(rs.getString("name"));

                                                projects.add(project);

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    DbUtil.closeAll(rs, stmt, con);

                        }

                        return projects;

            }

}

package com.lara.db.dao;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;

import com.lara.db.util.DbUtil;

import com.lara.entity.Skill;

public class SkillDAO

{

            public static List<Skill> readAllSkills()

            {

                        List<Skill> skills = new ArrayList<>();

                        Connection con = null;

                        Statement stmt = null;

                        ResultSet rs = null;

                        try

                        {

                                    con = DbUtil.getConnection();

                                    stmt = con.createStatement();

                                    rs = stmt.executeQuery("select id, name from skill");

                                    Skill skill = null;

                                    while(rs.next())

                                    {

                                                skill = new Skill();

                                                skill.setId(rs.getInt("id"));

                                                skill.setName(rs.getString("name"));

                                                skills.add(skill);

                                    }

                        }

                        catch(SQLException ex)

                        {

                                    ex.printStackTrace();

                        }

                        finally

                        {

                                    DbUtil.closeAll(rs, stmt, con);

                        }

                        return skills;

            }

}

package com.lara.client;

import java.util.List;

import java.util.Scanner;

import com.lara.db.dao.EducationDAO;

import com.lara.db.dao.EmployeeDAO;

import com.lara.db.dao.GenderDAO;

import com.lara.db.dao.ProjectDAO;

import com.lara.db.dao.SkillDAO;

import com.lara.entity.Address;

import com.lara.entity.Education;

import com.lara.entity.Employee;

import com.lara.entity.Gender;

import com.lara.entity.Project;

import com.lara.entity.Skill;

public class EmployeeManager

{

            public static void main(String[] args)

            {

                        Scanner sc = new Scanner(System.in);

                        System.out.println("Enter 1 for Inserting Employee");

                        System.out.println("Enter 2 for Searching an Employee");

                        int action = sc.nextInt();

                        if(action == 1)

                        {

                                    insert(sc);

                        }

                        else if(action == 2)

                        {

                                    //search(sc);

                        }

                        else

                        {

                                    System.out.println("Input is not proper");

                                    System.out.println("Enter 1 for insert and 2 for search");

                        }

            }

            private static void insert(Scanner sc)

            {

                        Address add = new Address();

                        Employee emp = new Employee();

                        emp.setAddress(add);

                        /* Gender selection */

                        List<Gender> genders = GenderDAO.readAllGenders();

                        System.out.println("Please select Gender");

                        for(Gender gender : genders)

                        {

                                    System.out.print("enter " + gender.getId() + " ");

                                    System.out.println("for " + gender.getName());

                        }

                        emp.setGenderId(sc.nextInt());

                        /* Education selection */

                        List<Education> educations = EducationDAO.readAllEducations();

                        System.out.println("Please select education");

                        for(Education education : educations)

                        {

                                    System.out.print("enter " + education.getId() + " ");

                                    System.out.println("for " + education.getName());

                        }

                        emp.setEducationId(sc.nextInt());

                        /* Project selection */

                        List<Project> projects = ProjectDAO.readAllProjects();

                        System.out.println("Please select project");

                        for(Project project : projects)

                        {

                                    System.out.print("enter " + project.getId() + " ");

                                    System.out.println("for " + project.getName());

                        }

                        emp.setProjectId(sc.nextInt());

                        /* Skills selection */

                        List<Skill> skills = SkillDAO.readAllSkills();

                        System.out.println("Please select skills by using comma as delimiter");

                        for(Skill skill : skills)

                        {

                                    System.out.print("enter " + skill.getId() + " ");

                                    System.out.println("for " + skill.getName());

                        }

                        String skillsStr = sc.next();

                        String skillsElements[] = skillsStr.split(",");

                        int skillIds[] = new int[skillsElements.length];

                        for(int i = 0; i < skillsElements.length; i++)

                        {

                                    skillIds[i] = Integer.parseInt(skillsElements[i].trim());

                        }

                        emp.setSkillIds(skillIds);

                        /* enter dob */

                        System.out.println("Please Enter Date of birth");

                        System.out.println("format --> DD-MON-YYYY");

                        emp.setDob(sc.next());

                        /* enter doj */

                        System.out.println("Please Enter Date of Join");

                        System.out.println("format --> DD-MON-YYYY");

                        emp.setDoj(sc.next());

                        /* first name */

                        System.out.println("Please enter first name");

                        emp.setFirstName(sc.next());

                        /* last name */

                        System.out.println("Please enter last name");

                        emp.setLastName(sc.next());

                        /* house no */

                        System.out.println("Please enter house no");

                        add.setHouseNo(sc.next());

                        /* street name*/

                        System.out.println("Please enter street name");

                        add.setStreetName(sc.next());

                        /* city name*/

                        System.out.println("Please enter city");

                        add.setCity(sc.next());

                        /* state name*/

                        System.out.println("Please enter state");

                        add.setState(sc.next());

                        /* username */

                        System.out.println("Please username");

                        emp.setUsername(sc.next());

                        /* password */

                        System.out.println("Please enter password");

                        emp.setPassword(sc.next());

                        EmployeeDAO.insertEmployee(emp);

            }

}