Hi all ,
I have to insert some data into orcl databse and select some data from orcl2 databse when my status is null.
Even after executing query in orcl2 status is null then we should stop the process for 5 minutes and then again poll the database and return untill we have some value for status .please let me know does my code works for that logic .If there are any changes please do let me know.It is very urgent please.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import oracle.jdbc.internal.OraclePreparedStatement;
import org.w3c.dom.*;
public class nrao{
public nrao() {
System.out.println("Inside constructor");
}
public String ReportTaskStatus(String taskId, String workDay,String duration)
{
System.out.println("eNTER THE DRAGON888888888888888888888888");
Context ctx = null;
Connection connDs = null;
OraclePreparedStatement opstmt = null;
ResultSet rsCan = null;
String status = null;
String outputMessage = "";
String jdbcURL = "jdbcracle:thin1521rcl";
String canonicalQuery="";
String interfaceId="";
String startDate="";
String startTimeDate="";
String endTimeDate="";
Date dt=new Date();
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").n ewInstance();
connDs = DriverManager.getConnection(jdbcURL, "scott", "tiger");
String insertStatement = "INSERT INTO REF_TBL (TASKID,WORKDAY) values (?,?)";
System.out.println("Came here ");
System.out.println("Before Inser Executgion");
opstmt = (OraclePreparedStatement)connDs.prepareStatement(i nsertStatement);
opstmt.setString(1,taskId);
opstmt.setString(2,workDay);
opstmt.setTimestamp(3,new Timestamp(dt.getTime()));
opstmt.executeUpdate();
}
catch (ClassNotFoundException ex) {System.err.println(ex.getMessage());}
catch (IllegalAccessException ex) {System.err.println(ex.getMessage());}
catch (InstantiationException ex) {System.err.println(ex.getMessage());}
catch (SQLException ex) {System.err.println(ex.getMessage());}
finally{
try{
connDs.commit();
connDs.close();
}catch(Exception e){
System.out.println("I erroed out");
e.printStackTrace();
}
}
if(status==null) {
status=getVsiiStatus(interfaceId,startDate);
status="Incomplete";
}
return status;
}
private String getVsiiStatus(String interfaceId,String startDate)
{
Context ctx = null;
Connection conn = null;
PreparedStatement stmtDs = null;
ResultSet resultSet = null;
String status= "";
String runMode="R";
String jdbcURL = "jdbcracle:thin:@1521rcl2";
String SQLQuery="";
int rowcount=0;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").n ewInstance();
conn = DriverManager.getConnection(jdbcURL, "scott", "tiger");
SQLQuery="SELECT INTF_ID,DTTM_STAMP,END_DTTM_STAMP FROM ig_session_log WHERE intfid=" + "'" + 118 + "AND RUN_MODE = "+ runMode +"'";
stmtDs = conn.prepareStatement(SQLQuery);
conn.setAutoCommit(false);
System.out.println("Before Row Count");
while(rowcount==0)
{
resultSet =stmtDs.executeQuery();
resultSet.next();
rowcount = resultSet.getRow();
System.out.println("rowcount now "+rowcount);
resultSet =stmtDs.executeQuery();
while(resultSet.next()) {
status = resultSet.getString("STATUS");
System.out.println("Status is"+status);
}
if(rowcount==0)
{
System.out.println("Before Sleep");
Thread.sleep(120000);
System.out.println("After Sleep");
SQLQuery="SELECT INTF_ID,DTTM_STAMP,END_DTTM_STAMP FROM ig_session_log WHERE intfid=" + "'" + 118 + "AND RUN_MODE = "+ runMode +"'";
stmtDs = conn.prepareStatement(SQLQuery);
resultSet = stmtDs.executeQuery();
if (resultSet.next())
{
status = resultSet.getString("INTF_STATUS");
}
}
}
}
catch(InterruptedException ex){System.err.println(ex.getMessage());}
catch (ClassNotFoundException ex) {System.err.println(ex.getMessage());}
catch (IllegalAccessException ex) {System.err.println(ex.getMessage());}
catch (InstantiationException ex) {System.err.println(ex.getMessage());}
catch (SQLException ex) {System.err.println(ex.getMessage());}
finally{
}
try{
conn.close();
}catch(Exception e){
System.out.println("whether connection closed");
e.printStackTrace();
}
System.out.println(" STATUS: "+status);
status="Complete";
return status;
}
public static void main(String args[]){
nrao nr = new nrao();
String status=nr.ReportTaskStatus("20","21","14");
System.out.println("dddd"+status);
}
}
please its very urgent