package com;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
import com.mysql.jdbc.Driver;
public class Demo1_Attack {
public static void main(String[] args) throws SQLException {
DriverManager.registerDriver(new Driver());
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/gjp", "root", "12");
Statement sta = con.createStatement();
Scanner sc = new Scanner(System.in);
System.out.println("请您输入用户名");
String username = sc.nextLine();
System.out.println("请您输入密码:");
String password = sc.nextLine();
String sql = "Select * from admin where username = '"+username+"' and password = '"+password+"'";
System.out.println(sql);
ResultSet result = sta.executeQuery(sql);
while(result.next()) {
String un = result.getString("username");
int pw = result.getInt("password");
System.out.println(un + " " + pw);
}
result.close();
sta.close();
con.close();
}
}
|
|