单击按钮后,我试图向我的 mysql 数据库发送一些信息,但我的屏幕冻结然后退出。这是代码:
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
try
{
new SendInfo(email.getText().toString(),password.getText().toString());
}catch(Exception e){
error.setText((CharSequence) e);
}
}
});
这是 SendInfo 类:
public SendInfo(String email, String pass) throws Exception
{
Connection conn = null;
String url = "jdbc:mysql://ip...:3306/"; // info changed
String dbName = "db"; //info changed
String driver = "com.mysql.jdbc.Driver";
String userName = "user"; //info changed
String password = "pass"; //info changed
String table = "users";
Class.forName(driver).newInstance();
DriverManager.setLoginTimeout(100);
conn = DriverManager.getConnection(url+dbName,userName,password);
Statement st = conn.createStatement();
java.util.Calendar cal = java.util.Calendar.getInstance();
java.util.Date utilDate = cal.getTime();
java.sql.Date sqlDate = new Date(utilDate.getTime());
st.executeUpdate("INSERT INTO users VALUES('1','Komal','asd',"+sqlDate+")");
conn.close();
}
我什至没有使用我得到的值作为参数来使它更容易,但它仍然不起作用。