Please check the code for the errors
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 = "jdbc:oracle:thin1521:orcl";
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 = "jdbc:oracle:thin:@1521:orcl2";
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
Re: Please check the code for the errors
Quote:
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.
Copied someone else's homework, huh? Recommended reading:
How To Ask Questions The Smart Way
db
Re: Please check the code for the errors
no it is my home work if you know solution please let me know
thanks in advance
Re: Please check the code for the errors
I will reiterate what I've said time and again...please flank your code with the [highlight=java][/highlight] tags. It makes the code much more readable, and as a result helps you receive answers to your question(s). In the past I have done this for you, however this time I encourage you to edit your post above using these tags.
Re: Please check the code for the errors
i have higligted the code where iam facing errors iam getting the following error
Before Inser Executgion
ORA-01747: invalid user.table.column, table.column, or column specification
Before Row Count
ORA-01722: invalid number
Re: Please check the code for the errors
ORA-01722
Looks like a String.
Re: Please check the code for the errors
Quote:
Originally Posted by
nrao
i have higligted the code
Once again, highlighting in bold doesn't do much as far as readability. Place the code between the highlight tags. Not doing so results in code which can be virtually impossible to read, and not doing so after being told to do so this many times is coming across as quite disrespectful.
Like this:
[highlight=java]Your Code Goes Here[/highlight]
or alternatively, like this:
[code]Your Code Goes Here[/code]
If you are still unclear how to do so, ask.
Re: Please check the code for the errors
it is unclear can you please explain me in detail
Re: Please check the code for the errors
Code java:
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);
}
}
Re: Please check the code for the errors
RE Javapenguin: "Give a person a fish, you feed them for a day. Teach them to fish, you feed them for life..."
Quote:
it is unclear can you please explain me in detail
nrao: When you enter code into the text area of the forums, start with [highlight=java] and end the code with [/highlight]. You could also type into the text area of the forum [highlight=java][/highlight], place the cursor between the the two, and paste your code. For example,
[highlight=java][/highlight]
I can now place code between the highlight tags
[highlight=java]
public class Demo{
public static void main(String[] args){
System.out.println("Hello World");
}
}
[/highlight]
The forum software will automatically format the code when these tags are used, for the example above this results in the following:
Code java:
public class Demo{
public static void main(String[] args){
System.out.println("Hello World");
}
}