JDBC simulated landing

 

package com.oracle.demo01;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class Demo08 {
    public static void main(String[] args){

        // get the object pre- 
        String SQL = "the SELECT COUNT (*) from the User the WHERE uname and pwd = =??" ;
        PST the PreparedStatement = null ;
         the try {
             // call JDBCUtils.getconn () -> custom classes 
            PST = JDBCUtils.getconn () the prepareStatement (SQL);.
        } catch (SQLException e1) {
            
            e1.printStackTrace ();
        }
        
        Scanner sc=new Scanner(System.in);
        System.out.println ( "Please enter your user name:" );
        String name=sc.next();
        System.out.println ( "Please enter your password:" );
        String pwd=sc.next();
        
        the try {
             // execute query 
            pst.setString (1 , name);
            pst.setString(2, pwd);
            Rs ResultSet = pst.executeQuery ();
             // see if the success 
            int COUNT = 0 ;
             the while (rs.next ()) {
                count=rs.getInt(1);
            }
            if (count>0) {
                System.out.println ( "login success" );
            }else{
                System.out.println ( "login failed" );
            }
            
        } catch (SQLException e) {
            
            e.printStackTrace ();
        } The finally {
             // release resources 
            the try {
                sc.close();
                pst.close();
                
            } catch (SQLException e) {
                
                e.printStackTrace ();
            }
        }
    }
}
                

 

.

Guess you like

Origin www.cnblogs.com/l1314/p/12148126.html