After calling the Movie_genre
class I still get a null
value in the phno variable outside the parameterised constructor Movie_genre
.
Why does that happen and how can I fix it?
phno=jTextField1.getText();
String p1=new String(jPasswordField1.getPassword());
String p2="";
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/show_booking","root","123456");
Statement stmt=conn.createStatement();
String query="Select Password from login where Phone_no='"+phno+"';";
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
p2=rs.getString("Password");
}
if(p1.equals(p2))
{
JOptionPane.showMessageDialog(this,"Login successful");
Movie_genre obj1=new Movie_genre(phno);
Movie_genre obj=new Movie_genre();
obj.setVisible(true);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
Here's the Movie_genre class.
public Movie_genre(String phno)
{
phno1=phno;
System.out.println(phno1+"sidhflf");
}
public Movie_genre()
{
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println(phno1);
Action obj1=new Action(phno1);
Action obj=new Action();
obj.setVisible(true);
}
phno=jTextField1.getText().toString();
String p1=new String(jPasswordField1.getPassword());
String p2="";
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/show_booking","root","123456");
Statement stmt=conn.createStatement();
String query="Select Password from login where Phone_no='"+phno+"';";
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
p2=rs.getString("Password");
}
if(p1.equals(p2))
{
JOptionPane.showMessageDialog(this,"Login successful");
Movie_genre obj1=new Movie_genre(phno);
Movie_genre obj=new Movie_genre();
obj.setVisible(true);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.