【问题标题】:Validate username and password in phpmyAdmin在 phpmyAdmin 中验证用户名和密码
【发布时间】:2015-04-13 09:02:38
【问题描述】:

我正在尝试使用用户名和密码验证数据库 (phpMyadmin)。我需要在所有表(我的数据库中的 25 个表)中搜索以检查给定的用户名和密码是否存在(身份验证)。谁能提供查询以使用给定的用户名和密码搜索整个表?

下面是我的代码

public class Dbclass {

    /**
     * @param args
     */
    Connection conn = null;
    Statement statement = null;
    ResultSet resultSet = null;
    ResultSetMetaData metaData = null;
    String DB_URL="com.mysql.jdbc.Driver";
    String USER="java";
    String PASS="redhat";
    String username;
    String password;
    ResultSet rs;
    public ResultSet dbConnection(String query)
    {

        //STEP 2: Register JDBC driver
        try {
            Class.forName("com.mysql.jdbc.Driver");

            //STEP 3: Open a connection
            System.out.println("Connecting to database...");
            try {
                conn = DriverManager.getConnection(DB_URL,USER,PASS);

                //STEP 4: Execute a query
                System.out.println("Creating statement...");
                Statement stmt = conn.createStatement();

                //sql = "SELECT username,password FROM Employees";
                rs = stmt.executeQuery(query);

                while(rs.next()){
                    //Retrieve by column name
                    username  = rs.getString("user_name");
                    password = rs.getString("password");

                    //Display values
                    System.out.print("User_name: " + username);
                    System.out.print(",Password: " + password);
                }
                Authentication obj=new Authentication();
                obj.userLogin(username,password);

                //STEP 6: Clean-up environment
                //rs.close();
                //return rs;
                stmt.close();
                conn.close();
            } catch (SQLException e) {
                //TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (ClassNotFoundException es) {
            //TODO Auto-generated catch block
            es.printStackTrace();
        }
        finally{
            //finally block used to close resources
            try{
                if(conn!=null){
                    conn.close();
                }
                if (rs != null) {
                    rs.close();
                }
            }catch(SQLException se){
                se.printStackTrace();
            }//end finally try
        }//end try
        return rs;
    }
}

【问题讨论】:

  • 请添加您迄今为止尝试过的代码,明智的......
  • @jean 添加了代码

标签: java mysql phpmyadmin


【解决方案1】:

我猜你正在寻找 where 子句。如下所示。

SELECT username,password FROM Employees where username='usernm' and password='pwd'

如果需要,您可以添加 UNION 以合并更多此类查询,但由于性能问题不推荐。

【讨论】:

    猜你喜欢
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2013-12-26
    • 2016-01-24
    • 2019-06-27
    相关资源
    最近更新 更多