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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!