Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Please check the code for the errors

  1. #1
    Member
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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 = "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
    Last edited by nrao; November 16th, 2010 at 03:33 PM.


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Please check the code for the errors

    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

  3. #3
    Member
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

  5. #5
    Member
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  6. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Please check the code for the errors

    ORA-01722

    Looks like a String.

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Please check the code for the errors

    Quote Originally Posted by nrao View Post
    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.

  8. #8
    Member
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please check the code for the errors

    it is unclear can you please explain me in detail

  9. #9
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Please check the code for the errors

    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);
     
     
    }
     
    }

  10. #10
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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..."

    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:

    public class Demo{
        public static void main(String[] args){
            System.out.println("Hello World");
        }
    }

Similar Threads

  1. Check this code out
    By jwill22 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 11th, 2010, 08:34 PM
  2. how to check the value
    By javaking in forum Java Servlet
    Replies: 2
    Last Post: July 22nd, 2010, 06:56 AM
  3. How to check whether the string contains only the specified characters ????
    By j_kathiresan in forum Java Theory & Questions
    Replies: 3
    Last Post: April 30th, 2010, 08:49 AM
  4. Can Anyone Check This Link
    By arpitgadle in forum Java Servlet
    Replies: 5
    Last Post: October 7th, 2009, 08:56 AM
  5. Problem in AWT and IFrame implementaion
    By AZBOY2000 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 24th, 2009, 03:41 AM