I am trying to register a user (using java, Java swing). I am able to get it to be inserted into the database but its throwing null pointer. I checked the internet for null pointer to handle it and what it said was not initializing a variable and using it. And referring to a null object. But in my code i cant find it. Please help.
public class registerr extends javax.swing.JFrame {
Connection conn;
OracleResultSet rs = null;
OraclePreparedStatement pst= null;
public registerr() {
initComponents();
connect();
}
public void connect()
{
// connection with Oracle DB
}
Clicking the register button, the value of texfield gets added to Database but then throws null pointer exception
private void regActionPerformed(java.awt.event.ActionEvent evt) {
try{
String fname = FnameTF.getText().trim();
String lname = LnameTF.getText().trim();
String uname = UnameTF.getText().trim();
String pass1 = Pass1TF.getText().trim();
String pass2 = Pass2TF.getText().trim();
String sqli = "insert into login"
+ "(fname, lname,uname, pass)"
+ " values ('"+FnameTF.getText()+"','"+LnameTF.getText()+"','"+UnameTF.getText()+"','"+Pass1TF.getText()+"')";
pst = (OraclePreparedStatement) conn.prepareStatement(sqli);
pst.executeUpdate(sqli);
pst.close();
int count = 0;
if(uname.equals("") || fname.equals("") || lname.equals("") || Pass1TF.getText().equals("") ||Pass2TF.getText().equals(""))
{
System.out.println("Please fill in all the fields");
}
else if(pass1.equals(pass2))
{
}
else {
System.out.println("Passwords do not match");
}
while (rs.next())
{
count++;
}
if(count == 1)
{
JOptionPane.showMessageDialog(null, "Please use new value for username");
System.out.println("Success");
}
else
{
System.out.println("Successfully registered");
JOptionPane.showMessageDialog(null, "Successfully registered!");
}
}
catch(Exception ex)
{
ex.printStackTrace(System.out);
}
}
Here is the stack trace
run:
Connected
java.lang.NullPointerException
at dbms.registerr.regActionPerformed(registerr.java:225)
at dbms.registerr.access$000(registerr.java:18)
at dbms.registerr$1.actionPerformed(registerr.java:87)
at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at
javax.swing.AbstractButton$Handler.actionPerformed
(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed
(DefaultButtonModel.java:402)
at javax.swing.JToggleButton$ToggleButtonModel.setPressed
(JToggleButton.java:308)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased
(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent
(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.
doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.
doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.
doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters
(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter
(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
BUILD SUCCESSFUL (total time: 25 seconds)