see the designing part and library connection part in video:
Source Code:
Connection code inside the class!
Connection con = null;
PreparedStatement pst =null;
ResultSet rs = null;
Code Inside the login button!
Source Code:
Connection code inside the class!
Connection con = null;
PreparedStatement pst =null;
ResultSet rs = null;
Code Inside the login button!
String sql="select * from login where username=? and password=?";
try{
con = DriverManager.getConnection("jdbc:mysql://localhost/testsql","root","");
pst=con.prepareStatement(sql);
pst.setString(1, user.getText());
pst.setString(2,pass.getText());
rs=pst.executeQuery();
if(rs.next())
{
JOptionPane.showMessageDialog(null,"username and password matched");
}
else
{
JOptionPane.showMessageDialog(null, "username and password do not matched");
}}
catch(SQLException | HeadlessException ex)
{
JOptionPane.showMessageDialog(null,ex);
}
No comments:
Post a Comment