我试图在点击按钮后向我的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();
}
我甚至没有使用我获得的值作为参数来使它更容易,但它仍然无法正常工作。
答案 0 :(得分:0)
看起来以下行出错:
error.setText((CharSequence) e);
将其更改为
error.setText(e.toString());
修好了。