Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSF
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JSF
java.lang.NullPointerException
james tony
Greenhorn
Posts: 1
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hey i was wonder what i was doing wrong. i keep getting this error
package Student; import java.sql.*; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean @SessionScoped public class Login { private String username =""; private String password =""; private PreparedStatement pstmt; private ResultSet rs; /** * Initialize the database */ public Login() { initializeJdbc(); } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } private boolean isRquiredFieldsFilled() { return !(username == null || password == null || username.trim().length() == 0 || password.trim().length() == 0); } public String processSubmit() { if (isRquiredFieldsFilled()) { return "confirminfo"; } else { return ""; } } public String getRequiredFields() { if (isRquiredFieldsFilled()) { return ""; } else { return "Username and Password are required"; } } public String getInput() { return "<p style=\"color:red\">You entered <br />" + "Username: " + username + "<br />" + "Password: " + password + "<br />"; } /** Initialize database connection */ private void initializeJdbc() { try { // Explicitly load a MySQL driver Class.forName("com.mysql.jdbc.Driver"); System.out.println("Driver loaded"); // Establish a connection Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost/test", "scott", "tiger"); // Create a Statement pstmt = conn.prepareStatement("Select username, password from studentaccount" + " where username = ? and password = ? "); } catch (Exception ex) { System.out.println(ex); } } /** Store an address to the database */ public String getInfo() throws SQLException{ String action = "studentlogin"; pstmt.setString(1, username); pstmt.setString(2, password); pstmt.executeQuery(); if(rs.next()) { action = "studentpage"; return action; } return action; } }
Confirminfo.xhtml
<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <title>Confirm Student Registration</title> </h:head> <h:body> <h:form> <h:outputText value= "Do you want to Process" style="font-weight: bold"/> <h:outputText escape="false" style="color:red" value="#{login.input}" /> <h:commandButton value="Yes" action = "#{login.getInfo()}"/> <h:commandButton value="No" action = "studentlogin"/> </h:form> </h:body> </html>
The error is
Caused by: java.lang.NullPointerException at Student.Login.getInfo(Login.java:95) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.el.parser.AstValue.invoke(AstValue.java:264) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
Mark Reyes
Ranch Hand
Posts: 426
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can you do something like this
/** Store an address to the database */ public String getInfo() throws SQLException{ String action = "studentlogin"; pstmt.setString(1, username); pstmt.setString(2, password); rs = pstmt.executeQuery(); if(rs!=null && rs.next()) { action = "studentpage"; return action; } return action; }
Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
commandLink not working in datatable+jsf2.0
Target Unreachable, identifier resolved to null (JSF 2.0)
JSF 2.0 Login
context.getRequest()).getRequestDispatcher("/j_spring_security_check") returns null
JEE example with EJB, JSF is not working
More...