- import java.util.*;
- import java.sql.*;
- public class DBtest {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String driver = "com.mysql.jdbc.Driver" ;
- //String url = "jdbc:mysql://localhost/javadb";
- String user = "root" ;
- String pd = "123456" ;
- try {
- Class.forName("com.mysql.jdbc.Driver" );
- String url="jdbc:mysql://localhost/javadb?user=root&password=123456" ;
- Connection conn = DriverManager.getConnection(url);
- //Connection conn = DriverManager.getConnection(url,user,pd);
- Statement stmt = conn.createStatement();
- String name;
- String password;
- System.out.print("请输入用户名:" );
- Scanner sc= new Scanner(System.in);
- name = sc.next();
- System.out.print("请输入密码:" );
- password = sc.next();
- String sql = "select count(*) from admin where username = '" +name+ "' and passwd = '" +password+ "'" ;
- ResultSet rs = stmt.executeQuery(sql);
- rs.next();
- int count = rs.getInt( 1 );
- if (count > 0 )
- System.out.println("登陆成功!" );
- else
- System.out.println("登陆失败!" );
- rs.close();
- stmt.close();
- conn.close();
- }catch (Exception e){
- System.out.print("程序错误!" );
- }
- }
- }
小小登陆程序
最新推荐文章于 2025-08-15 10:57:29 发布