Results 1 to 9 of 9

Thread: Output error

  1. #1
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Output error

    i am trying to connect with oracle 11g xe release 2 but it is not showing any output

    Java Code:
    
    import java.sql.*;
    /**
     *
     * @author Dev Vivk
     */
    public class Jcon{
        public static void main(String Dev[]){
            try{
           
    	         Class.forName("oracle.jdbc.driver.OracleDriver");
            
                 Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "password");
           
    	                 String n="vivek";
    					 int i=10;
                       	   
    	   
                 Statement s=con.createStatement();
    			 s.executeUpdate("create table emp1(name varchar(20),salary number)");
    			 s.close();
    			 
    			 PreparedStatement ps=con.prepareStatement("insert into emp1 value(?,?)");
    			 ps.setString(1,n);
    			 ps.setInt(2,i);
    			 ps.executeUpdate();
    			 ps.close();
                  
    			  
    			  //ps=c.prepareStatement("select * from emp1);
    			  ps=con.prepareStatement("select * from emp1 where salary=?");
    			  ps.setInt(1,i);
    			  
                 ResultSet rs=ps.executeQuery();
           
           while(rs.next()){
               System.out.println("name "+rs.getString(1));
    		   System.out.println("name "+rs.getString(2));
               
           }
            }catch(Exception e){}
           }
        }


    Output error-capture.jpg



    how to resolve?

    Thanks

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    390
    Rep Power
    4

    Default Re: Output error

    First thing I would do is to check whether the table has been created in the DB and whether it contains the data you have inserted.

    It also bites you here that you are not handling your exception in line 40. A simple printout of the stack trace would probably give valuable insights.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Output error

    First off don't leave the catch block empty like that.
    Change it to this:
    Java Code:
    }catch(Exception e){}
        e.printStacktrace();
    }
    and then see what happens when you run that code.

    ETA: Ah! Ninja'd!!
    :)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: Output error

    java program console output

    Output error-capture.jpg

    Sql console output


    Output error-sql.jpg

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Output error

    The command (as the error in the SQL console implies) is:
    DESCRIBE emp1;

    though you might need the schema name as well, depending.

    In any case, you ought to be getting a stack trace to show you exactly what line is throwing that error.
    However, we can guess it's the CREATE TABLE call.

    What has likely happened is the table was created on one run, which then failed on something else.
    Because you had nothing in your catch block to see the error you got no output at all.
    Then, when you ran it again, it starts throwing the above error on the CREATE TABLE, since the table already exists.

    Normally you wouldn't need to create the tables like that in code, for this reason.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: Output error

    so what to do now, how to print the result ?

  7. #7
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: Output error

    now it showing this error after drop the table and run the program again
    Output error-capture.jpg

  8. #8
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: Output error

    everything is solve thanks to all for this supporting

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Output error

    You still seem to be not printing the stack trace.
    You ought to get into the habit of doing that (see post #3) as you are losing a lot of useful information.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Linked list (error in output)
    By urnion in forum New To Java
    Replies: 2
    Last Post: 03-12-2017, 01:28 PM
  2. methods: no error: output=0.0
    By nidhigarg06 in forum New To Java
    Replies: 3
    Last Post: 09-26-2013, 08:23 AM
  3. output error
    By mentoes178 in forum New To Java
    Replies: 1
    Last Post: 06-17-2013, 07:39 PM
  4. Error output
    By Kartright in forum New To Java
    Replies: 5
    Last Post: 05-30-2013, 05:28 AM
  5. OutPut Error :/
    By socboy6579 in forum New To Java
    Replies: 2
    Last Post: 12-12-2010, 09:03 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •