Results 1 to 5 of 5

Thread: JDBC Problem

  1. #1
    nitishjtm is offline Member
    Join Date
    Sep 2010
    Posts
    30
    Rep Power
    0

    Post JDBC Problem

    Hi, I am Nitish Kumar. I have written the following program of jdbc:

    package nitish.jdbc.first;
    import java.sql.*;
    import java.util.*;

    public class JdbcEx1{
    public static void main(String []s){
    try{
    Class c = Class.forName("oracle.jdbc.driver.OracleDriver");
    Driver d = (Driver)c.newInstance();
    Properties p = new Properties();
    p.setProperty("user","scott");
    p.setProperty("password","tiger");
    Connection con = d.connect("jdbc:oracle:oci8@xe",p);
    Statement st = con.createStatement();
    String query = "insert into student_details values(1,'Nitish',5000);";
    int recordsInserted = st.executeUpdate(query);
    System.out.println("Record Inserted::"+ recordInserted);
    }//try
    catch(ClassNotFoundException cnfe){}
    catch(InstantiationException ine){}
    catch(IllegalAccessException iae){}
    catch(SQLException sqle){}
    }//main
    }//class

    The problem is that I am not getting the output. Means I am unable to connect to the database. When executing this program, it returns nothing. Instead, it should return an integer value. Even I changed the drivers also, but that also didn't help me. I am using Oracle 10g Enterprise Edition release 2. Please suggest me what to do.

    Thank you

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, don't ignore exceptions. Add a printStackTrace to everyone of those catch blocks. How do you think to ever hear the siren when you've plugged your ears?

  3. #3
    nitishjtm is offline Member
    Join Date
    Sep 2010
    Posts
    30
    Rep Power
    0

    Post

    Quote Originally Posted by masijade View Post
    Well, don't ignore exceptions. Add a printStackTrace to everyone of those catch blocks. How do you think to ever hear the siren when you've plugged your ears?
    Thanks, but the problem was due to ; which I inserted in the last of query. Now, I always use behaviors to catch the exceptions.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by nitishjtm View Post
    Thanks, but the problem was due to ; which I inserted in the last of query. Now, I always use behaviors to catch the exceptions.
    And actually placing something in the catch blocks would have told you that.

    Edit: And, BTW, I have no idea what you mean by
    Now, I always use behaviors to catch the exceptions.
    . If you mean some API designed to allow you to "ignore" exceptions in your coding and still be able to handle them, then it sounds like a simple crutch for someone not willing to do the work properly. If that's not what you mean, then I'm sorry I said that, but I thought it needed to be said, if that is what it is.
    Last edited by masijade; 11-18-2010 at 07:40 AM.

  5. #5
    nitishjtm is offline Member
    Join Date
    Sep 2010
    Posts
    30
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    Edit: And, BTW, I have no idea what you mean by . If you mean some API designed to allow you to "ignore" exceptions in your coding and still be able to handle them, then it sounds like a simple crutch for someone not willing to do the work properly. If that's not what you mean, then I'm sorry I said that, but I thought it needed to be said, if that is what it is.
    Extremely sorry sir, I did't wrote clearly. I mean to say, I use printStackTrace() or getMessage() for getting description of exception.

Similar Threads

  1. Problem with Jdbc
    By enjoybullife in forum Java Servlet
    Replies: 4
    Last Post: 05-21-2010, 10:19 AM
  2. jdbc problem!!! pls help
    By dilanka007 in forum New To Java
    Replies: 1
    Last Post: 04-14-2010, 01:16 PM
  3. jdbc problem!!! pls help
    By dilanka007 in forum New To Java
    Replies: 5
    Last Post: 01-16-2010, 05:07 PM
  4. problem with jdbc in jsp
    By nishant.4545 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 08-29-2009, 01:31 PM
  5. JDBC problem
    By peiceonly in forum Threads and Synchronization
    Replies: 2
    Last Post: 08-03-2007, 01:42 PM

Posting Permissions

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