Here is Step by Step . I use NetBeans Ide.
2. Create jFrameform , Name it Login window And Design it like this .
3. Import to jar file mysql-connector-java-5.1.22-bin in to library
4. Crate class Dbcon.java And write code like this,
public static Connection mycon(){
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/login","root","");
//localhost is host name
return con;
} catch (ClassNotFoundException | SQLException e) {
System.out.println(e);
return null;
}
}
5. Create database (MySQL ) login . i am use wamp server .
6. import sql ( Download sql file ) file or Create Table user and fled
User_Nam varchar(100) and Password int (11)
7. Create jFrame form : Main
8. Code Write to login Bottom
String uid ;
String uname = txt_u.getText();
String psswd = txt_pw.getText();
try {
String sql = "SELECT * FROM user WHERE User_Name = ? AND Password = ? ";
pst =con.prepareStatement(sql);
pst.setString(1, uname);
pst.setString(2, psswd);
rs = pst.executeQuery();
if(rs.next()){
this.dispose();
Main ho = new Main();
ho.setVisible(true);
}else {
JOptionPane.showMessageDialog(rootPane, "UserName Or Password is Wrong");
txt_u.requestFocus();
}
} catch (Exception e) {
System.out.println(e);
}
txt_u.setText("");
txt_pw.setText("");
9. Run Project .
👌 Download Code from GitHub
Tags:
Javaproject