0
继承人我的login屏幕。顶部的editText是“txtbxStudentUsername”,底部的editText是“txtbxStudentLunchID”。Android - JDBC登录
我正在使用jdbc来与我们的phpadmin wamp mysql服务器在局域网上建立联系,因此不会出现因特网SQL问题。
我知道我在阅读edittext字段并在数据库中比较它们时遇到问题。还有syntax of my database connection有什么建议吗?这是我的代码。
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();
}
}
两德公司为拉皮条双倍剂量的? – dtown123 2012-04-16 17:50:08
不确定在Android应用程序中使用MySQL驱动程序是否是个好主意。我认为你必须做的是在服务器端写一些东西,你可以从Android发布POST请求。就像:http://yourserver.com/login.php – Cristian 2012-04-16 17:50:19
请注意,'localhost'将是你的android设备,而不是你的局域网中的设备 – AxelTheGerman 2012-04-16 18:48:07