Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////TEST CLASS////////
- package test;
- import java.sql.*;
- import javax.swing.JOptionPane;
- public class Test {
- Connection conn = null;
- public static Connection ConnectDB(){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn= DriverManager.getConnection("jdbc:mysql://localhost/db?user=root");
- JOptionPane.showMessageDialog(null,"Connected to DB");
- return conn;
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null,e);
- return null;
- }
- }
- }
- ——————————
- /////////LOGIN FORM//////////
- Connection conn = null;
- PreparedStatement pst = null;
- ResultSet rs = null;
- private void b1ActionPerformed(java.awt.event.ActionEvent evt) {
- conn=Test.ConnectDB();
- String Sql = "Select * from people where Fname=? and Lname=?";
- try{
- pst=conn.prepareStatement(Sql);
- pst.setString(1,t1.getText());
- pst.setString(2,t2.getText());
- rs=pst.executeQuery();
- if(rs.next()){
- JOptionPane.showMessageDialog(null,"Welcome");
- Welcome w = new Welcome();
- w.setVisible(true);
- }
- else{
- JOptionPane.showMessageDialog(null,"Incorrect","Acces Denied",JOptionPane.ERROR_MESSAGE);
- }
- } catch(Exception e){
- JOptionPane.showMessageDialog(null,e);
- }
- }
- —————————————
- /////////////////WELCOME FORM//////////
- Just a label saying you are welcome
Add Comment
Please, Sign In to add comment