繁体   English   中英

Android-JDBC登录

[英]Android - JDBC Login

这是我的登录屏幕。 顶部的editText是“ txtbxStudentUsername”,底部的editText是“ txtbxStudentLunchID”。

我正在使用jdbc连接到局域网上的phpadmin wamp mysql服务器,因此没有通过Internet的SQL问题。

我知道我在读取edittext字段并将它们在数据库中进行比较时遇到问题。 还有我数据库连接语法有什么建议吗? 这是我的代码。

    public void onGotoStudent(View View)
    {
        String url = "jdbc:mysql://localhost:3306/tardy_system";
        String user = "root_user";
        String pwd = "root";
        Connection con = DriverManager.getConnection(url, user, pwd);

        EditText username = (EditText)findViewById(R.id.txtbxStudentUsername);
        EditText password = (EditText)findViewById(R.id.txtbxStudentLunchID);

        String passChars;

        passChars = password.getText().toString();
        if(passChars!=null) 
        {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection) DriverManager.getConnection("jbdc:mysql://localhost/tardy_system/students","Matt_Glover","root");

            (PreparedStatement) prepstmt = con.prepareStatement("SELECT Username,Lunch_ID FROM Student where username=? and password=?");
            prepstmt.setString(1, username);
            prepstmt.setString(2, password);


            ResultSet rs;
            rs = prepstmt.executeQuery();

            boolean found = rs.next();
            if (found)
              System.out.println(rs.getString(1));
            prepstmt.close();
        }

        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1,username);
        ps.setString(2,password);
        ResultSet rs=password.executeQuery();
        if(rs.next()) {
           //found
        }
        else{
           //not found
        }
        rs.close();
        ps.close();
        conn.close();
    }
}

如果没有AsynTask,则无法与jdbc连接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM