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 2 of 2

Thread: unable to execute prepared statement

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

    Default unable to execute prepared statement

    my code
    package jdbcstatements;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
     
     
    import java.sql.SQLException;
     
     
     
     
     
    public class Insertion {
     
     
     
    	public static void main(String[] args) throws SQLException {
     
    		try {   
    	      Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    	      String url="jdbc:oracle:thin:@localhost:1521:orcl";
     
    	    Connection  con=DriverManager.getConnection(   url,   "scott", "tiger");
    	      System.out.println("connection created");	 
     
     
    try{
     
    	          String sql = "INSERT EMP VALUES(?)";
    	          PreparedStatement prest = con.prepareStatement(sql);
    	          BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    	          System.out.println("Enter employee name:");
    	          String ename = bf.readLine();
    	          prest.setString(2,ename);
    	          System.out.println("Enter salaryof employee:");
    	          int sal = Integer.parseInt(bf.readLine());
    	          prest.setInt(2, sal);
    	          int count = prest.executeUpdate();
    	          System.out.println(count + "row(s) affected");
    	          con.close();
    	        }
    	        catch (SQLException s){
    	          System.out.println("SQL statement is not executed!");
    	        }
    	      }
    	catch (Exception e){
    	      e.printStackTrace();
    	    }
     
     
     
    	}
    }

    error

    connection created
    Enter movie name:
    xxxx
    SQL statement is not executed!
    Last edited by copeg; November 11th, 2010 at 08:26 PM.


  2. #2
    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: unable to execute prepared statement

    Why swallow all the exception information....
    catch (SQLException s){
    s.printStrackTrace();//print the stack trace - this is important information
    System.out.println("SQL statement is not executed!");
    }
    What does the exception say?
    And finally, please use the code tags. It makes your code that much more readable.

Similar Threads

  1. Prepared Statement exceptions please help
    By nrao in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 11th, 2010, 08:16 PM
  2. unable to run log code
    By javaking in forum What's Wrong With My Code?
    Replies: 10
    Last Post: April 6th, 2010, 11:49 PM
  3. What is SNMP in Java?Hoe to execute code related to this?
    By jj_crazy_1 in forum Java Theory & Questions
    Replies: 0
    Last Post: April 5th, 2010, 10:47 PM
  4. How to execute a Java program independent of Netbeans.
    By ShaunB in forum Java Theory & Questions
    Replies: 4
    Last Post: January 19th, 2010, 06:23 AM
  5. how to execute a simple display without a main method
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 13th, 2010, 07:28 AM