public class MicroJDBCExampleStatement {

 

      String jdbcDriver = "oracle.jdbc.driver.OracleDriver";

      String jdbcURL = "jdbc:oracle:thin:@localhost:1521:TEST";

      String jdbcUserName = "myUserName";

      String jdbcPassword = "myPassword";

     

      public MicroJDBCExampleStatement(){

      }

 

      class EmployeeSelect extends MicroJDBCRecordImpl{

            int id;

            String name;

            String lastName;

 

            public String getSelectSql() {

                  return "SELECT id, name, lastname FROM Employee WHERE id = " + id;

            }

           

            public void select(ResultSet rs) throws SQLException {

                  name = rs.getString(2);

                  lastName = rs.getString(3);

            }

      }

     

      public void exampleSelect(int employeeId) throws MicroJDBCException{

           

            MicroJDBCDBase mdb = new MicroJDBCDBase();

            mdb.setConnection( jdbcDriver, jdbcURL, jdbcUserName, jdbcPassword);

           

            EmployeeSelect employee = new EmployeeSelect();

            employee.id = employeeId;

            mdb.selectRow(employee);

           

            log("EmployeeId:" + employee.id +

                        ", EmployeeName:" + employee.name +

                        ", EmployeeLastName:" + employee.lastName);

      }

     

      class EmployeeUpdate extends MicroJDBCRecordImpl{

            int id;

            String name;

            String lastName;

 

            public String getUpdateSql() {

                  return "UPDATE Employee set name='" +

                  name + "', lastname='" + lastName +"' WHERE id = " + id;

            }

      }

     

      public void exampleUpdate(int employeeId) throws MicroJDBCException{

           

            MicroJDBCDBase mdb = new MicroJDBCDBase();

            mdb.setConnection( jdbcDriver, jdbcURL, jdbcUserName, jdbcPassword);

           

            EmployeeUpdate employee = new EmployeeUpdate();

            employee.id = employeeId;

            employee.name = "John";

            employee.lastName = "Doe";

            mdb.update(employee);

           

      }

     

      class EmployeeInsert extends MicroJDBCRecordImpl{

            int id;

            String name;

            String lastName;

 

            public String getInsertSql() {

                  return "INSERT INTO Employee (id, name, lastName) VALUES (" +

                  id + ", '" +      name + "', '" + lastName +"')";

            }

      }

     

      public void exampleInsert(int employeeId) throws MicroJDBCException{

           

            MicroJDBCDBase mdb = new MicroJDBCDBase();

            mdb.setConnection( jdbcDriver, jdbcURL, jdbcUserName, jdbcPassword);

           

            EmployeeInsert employee = new EmployeeInsert();

            employee.id = employeeId;

            employee.name = "Joe";

            employee.lastName = "Done";

            mdb.insert(employee);

           

      }

     

      class EmployeeUpdateOrInsert extends MicroJDBCRecordImpl{

            int id;

            String name;

            String lastName;

 

            public String getInsertSql() {

                  return "INSERT INTO Employee (id, name, lastName) VALUES (" +

                  id + ", '" +      name + "', '" + lastName +"')";

            }

           

            public String getUpdateSql() {

                  return "UPDATE Employee set name='" +

                  name + "', lastname='" + lastName +"' WHERE id = " + id;

            }

      }

     

      public void exampleUpdateOrInsert(int employeeId) throws MicroJDBCException{

           

            MicroJDBCDBase mdb = new MicroJDBCDBase();

            mdb.setConnection( jdbcDriver, jdbcURL, jdbcUserName, jdbcPassword);

           

            EmployeeUpdateOrInsert employee = new EmployeeUpdateOrInsert();

            employee.id = employeeId;

            employee.name = "Joe33";

            employee.lastName = "Done33";

            mdb.updateOrInsert(employee);

           

      }

     

      class EmployeeDelete extends MicroJDBCRecordImpl{

            int id;

            String name;

            String lastName;

 

            public String getDeleteSql() {

                  return "DELETE FROM Employee WHERE id = " + id;

            }

      }

     

      public void exampleDelete(int employeeId) throws MicroJDBCException{

           

            MicroJDBCDBase mdb = new MicroJDBCDBase();

            mdb.setConnection( jdbcDriver, jdbcURL, jdbcUserName, jdbcPassword);

           

            EmployeeDelete employee = new EmployeeDelete();

            employee.id = employeeId;

            mdb.delete(employee);

           

      }

     

      public static void main(String[] args) {

            MicroJDBCExampleStatement tinyJDBCExample = new MicroJDBCExampleStatement();

            try{

                  tinyJDBCExample.exampleSelect(12);

            }catch (MicroJDBCException e){

                  e.printStackTrace();

            }

           

      }

 

      private void log(String line){

            System.out.println(line);

      }

}