Results 1 to 2 of 2
  1. #1
    mjz
    mjz is offline Member
    Join Date
    Mar 2009
    Posts
    6
    Rep Power
    0

    Default NullPointerException

    Hi,
    I need help on why am getting a NPE with the code below.I am connecting to Ora 11g using JDBC in OracleCon which works well but executing the SQL code throws an NPE.
    Thax.



    package zm.crb;

    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.ResultSet;

    public class User {
    private String username;
    private String password;
    private int alevel;
    private int manNo;
    private int deptID;
    private int x;
    String y;

    public User() {
    }
    public User(String username,String password) {
    this.username = username;
    this.password = password;
    }
    public User(int manNo,String username,String password, int alevel,int dept) {
    this.username = username;
    this.password = password;
    this.alevel= alevel;
    this.manNo=manNo;
    this.deptID=dept;
    }
    public String addUser(){
    OracleCon db = new OracleCon();
    Statement st = db.getScrollableStatement();
    try{
    if(db.connect()){
    String query="INSERT INTO mjzeko.Users VALUES('"+manNo+"','"+username+"', '"+password+"', '"+alevel+"','','','"+deptID+"')";
    st.executeUpdate(query);

    db.disconnect();
    return "You created a User";
    }
    else{
    return "No conn to DB Failure See DBA >>>";
    }

    }
    catch(SQLException e){
    e.printStackTrace();
    return "exception occured";
    }

    }


    public boolean aunthenticate1(String username,String password){
    OracleCon db = new OracleCon();
    Statement st2 = db.getScrollableStatement();
    try{
    if(db.connect()){
    String uquery = "Select * from mjzeko.users";
    ResultSet res = st2.executeQuery(uquery);
    while (res.next()){
    x=Integer.parseInt(res.getString(1));
    y=res.getString(2);
    System.out.print(x);
    System.out.print(y);
    st2.close();
    }
    return true;
    }
    else
    return false;
    }

    catch(Exception ex)
    { ex.printStackTrace();
    System.out.print("This is where I end up");
    return false;
    }
    }
    public static void main(String args[]){
    User c=new User("mjzeko","12345");
    System.out.print(c.aunthenticate1("mjzeko","12345" ));
    }
    }

    stackTrace:

    java.lang.NullPointerException This is where I end upfalse
    at zm.crb.User.aunthenticate1(User.java:74)
    at zm.crb.User.main(User.java:107)

  2. #2
    Join Date
    Aug 2009
    Posts
    21
    Rep Power
    0

    Default

    if u use
    Select * from mjzeko.users some time the record is fetched.but traversing
    record will be problametic.you specifiy the excat field names you want.
    EX: SELECT USER_NAME,PASS_WARD FROM tbl_user; something like this

    INSERT INTO mjzeko.Users VALUES('"+manNo+"','"+username+"', '"+password+"', '"+alevel+"','','','"+deptID+"')";

    u specify the filed name and values in the querys
    sure u will not get any problem
    :) javadeveloper

Similar Threads

  1. NullPointerException I NEED HELP
    By mayhewj7 in forum New To Java
    Replies: 2
    Last Post: 02-13-2009, 08:03 AM
  2. NullPointerException
    By Aika in forum New To Java
    Replies: 8
    Last Post: 11-18-2008, 11:34 PM
  3. NullPointerException
    By adeeb in forum AWT / Swing
    Replies: 3
    Last Post: 06-11-2008, 08:42 AM
  4. NullPointerException
    By mensa in forum Java 2D
    Replies: 5
    Last Post: 05-03-2008, 11:19 PM
  5. NullPointerException
    By Feng in forum New To Java
    Replies: 5
    Last Post: 11-24-2007, 07:51 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
  •