Results 1 to 2 of 2
Thread: NullPointerException
- 08-06-2009, 11:11 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 6
- Rep Power
- 0
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)
- 08-06-2009, 11:46 AM #2
Member
- Join Date
- Aug 2009
- Posts
- 21
- Rep Power
- 0
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
-
NullPointerException I NEED HELP
By mayhewj7 in forum New To JavaReplies: 2Last Post: 02-13-2009, 08:03 AM -
NullPointerException
By Aika in forum New To JavaReplies: 8Last Post: 11-18-2008, 11:34 PM -
NullPointerException
By adeeb in forum AWT / SwingReplies: 3Last Post: 06-11-2008, 08:42 AM -
NullPointerException
By mensa in forum Java 2DReplies: 5Last Post: 05-03-2008, 11:19 PM -
NullPointerException
By Feng in forum New To JavaReplies: 5Last Post: 11-24-2007, 07:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks