Thursday, July 26, 2018

Simple Oracle connection


Set UP

Download the driver.
       

public static Connection connect() {


    System.out.println("-------- Oracle JDBC Connection Testing ------");


    try {


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


    } catch (ClassNotFoundException e) {


        System.out.println("Where is your Oracle JDBC Driver?");
        e.printStackTrace();
        return null;


    }


    System.out.println("Oracle JDBC Driver Registered!");


    Connection connection = null;


    try {


        connection = DriverManager.getConnection(
                "jdbc:oracle:thin:@dbip/name:1521:$$", "user", "pw");


    } catch (SQLException e) {


        System.out.println("Connection Failed! Check output console");
        e.printStackTrace();
        return null;


    }


    if (connection != null) {
        System.out.println("You made it, take control your database now!");
    } else {
        System.out.println("Failed to make connection!");
    }


    return connection;
}







 public static void updateRecord(String flag,String id) throws SQLException {


        Connection dbConnection = null;
        Statement statement = null;


        String updateTableSQL = "update tablename"
               + " SET name = '"+flag+"' "
                 + "WHERE id = ''"+id+"";

        try {
            dbConnection = connect();
            statement = dbConnection.createStatement();


            System.out.println(updateTableSQL);


            // execute update SQL stetement        
   statement.execute(updateTableSQL);


            System.out.println("Record is updated to tablename table!");


        } catch (SQLException e) {


            System.out.println(e.getMessage());


        } finally {


            if (statement != null) {
                statement.close();
            }


            if (dbConnection != null) {
                dbConnection.close();
            }


        }


    }


//Returns the data
    public static Data selectRecordsFromTable() throws SQLException {


        Connection dbConnection = null;
        Statement statement = null;
//create your own data class to save the result
        Data data = new Data();


        String selectTableSQL = "select query";


        try {
            dbConnection = connect();
            statement = dbConnection.createStatement();


            System.out.println(selectTableSQL);


            // execute select SQL stetement
            
   ResultSet rs = statement.executeQuery(selectTableSQL);


            while (rs.next()) {


                 data.id= rs.getString("id");
                data.name=  rs.getString("name");
 


            }


        } catch (SQLException e) {


            System.out.println(e.getMessage());


        } finally {


            if (statement != null) {
                statement.close();
            }


            if (dbConnection != null) {
                dbConnection.close();
            }


        }
return data;
    }


//Data calss

public class Data {
    
public static String id ;  
public static String name ;


}


 

Thursday, July 19, 2018

CICS Screen Automation Frame Work

As400 Automation

Things Needed Before Start

  1. Java  Knowledge
  2. TestNG
Introduction To CICS Screen



Terminal Types

  1. TN5250
  2. TN3270

Architecture






Sample Code 

Login Function

public class Login extends FunctionBaseTN5250 {

    
    public static void loadBox(String stripAdress, String strbox) throws Exception {
        connectToBox(stripAdress, strbox);
        waitForScreenwithText("USER ID", 5);
    }

   
    public static void LoginToBox(String strUserName, String strPassword) throws Exception {

        sendText(strUserName, LoginPage.getRowNoUserNameField(), LoginPage.getColNoUserNameField());
        sendKeys(TAB);
        sendText(strPassword, LoginPage.getRowNoPasswordField(), LoginPage.getColNoPasswordField());
        sendKeys(ENTER);
    }

}


Login Page

public class T5250LoginPage {

private static int rowNumberUserNameField = 13;
private static int colNumberUserNameField = 41;

private static int rowNumberPasswordField = 14;
private static int colNumberPasswordField = 41;

}


Login Test

public class LoginTest  
{

    @BeforeClass    
    public void init(ITestContext iTestContext)
    {
    }
    @Test
    public static void PurchaseOrder() throws Exception{
         Login. loadBox(iPAddress, box);
         Login. LoginToBox(userName,password);
        

}


}