[Solved] Mysql java taking registration [closed]


Follow the steps:
1. Download Mysql and Install+ dwnload mysql-connector jar file.
2. in the mysql(u can connect using mysql command line client) provide ur pwd and get ready.
Put below code:
3. create database TEST
4. use TEST.
5. CREATE TABLE USER_DTLS (USERNAME VARCHAR2(100), PASS VARCHAR2(100)); creating tables
6. INSERT INTO USER_DTLS('user1', 'user1234');INSERT INTO USER_DTLS('user2', 'user1234'); creating users
7. To connect to mysql:

public Connection getConnection(){
    Connection con=null;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "TEST";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root"; 
    String password = "password";

    try {
        Class.forName(driver).newInstance();
        con = DriverManager.getConnection(url+dbName,userName,password);
        System.out.println("CONNECTION ESTABLISHED.");

    } catch (Exception e) {
        System.out.println("CONNECTION COULD NOT BE ESTABLISHED.");
        e.printStackTrace();
    }

    return con;

}

in JAVA:

Connection conn=getConnection();
PreparedStatement pst=conn.prepareStatement("select * from user_dtls where USERNAME =? and PASS=?");
pst.setString(username,1);
pst.setString(passwrd,2);
rs=pst.executeQuery();
if(rs.next()){
// HE is valid user
}else{
// INVALID
}

Hope this helps.

0

solved Mysql java taking registration [closed]