Question
JJAVA Can someone help me get rid of the database and instead check for username and password in a file(.txt) ? please keep in mind
JJAVA Can someone help me get rid of the database and instead check for username and password in a file(.txt) ?
please keep in mind that this is GUI
try { String driver = "com.mysql.jdbc.Driver"; Class.forName(driver); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/crm", "root", "3366"); System.out.println(con.toString()); String nm=jTextField1.getText(); String paas=jPasswordField1.getText(); String query = "SELECT * FROM login WHERE username='"+nm +"';";
System.out.println("Query :" + query); Statement st = con.createStatement(); ResultSet rs = st.executeQuery(query); int flag = 0; while (rs.next()) { String passw = rs.getString("password"); if (passw.equals(paas)) { JOptionPane.showMessageDialog(this,"Congrts U are authenticated" ); flag = 1; this.setVisible(false); Home frame = new Home(); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setVisible(true); } }
if (flag == 0) JOptionPane.showMessageDialog(this,"Wrong Username or password" ); //System.out.println(); con.close();
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started