我在以下代码中遇到一个问题:
public Menu menu;
public TextView tv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textv = (TextView)this.findViewById(R.id.mysql);
tv = textv;
Connect();
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.login:
Intent loginIntent = new Intent(this, LoginActivity.class);
startActivityForResult(loginIntent, LOGIN_REQUEST);
return true;
case R.id.register:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
protected void onStop(){
super.onStop();
}
protected void onDestroy(){
super.onDestroy();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == LOGIN_REQUEST){
if(resultCode == RESULT_OK){
}
}
super.onActivityResult(requestCode, resultCode, data);
}
private class Connect extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
String response = "";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, pass);
System.out.println("Database connection success");
String result = "Database connection success\n";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from login");
ResultSetMetaData rsmd = rs.getMetaData();
while(rs.next()) {
result += rsmd.getColumnName(1) + ": " + rs.getInt(1) + "\n";
result += rsmd.getColumnName(2) + ": " + rs.getString(2) + "\n";
result += rsmd.getColumnName(3) + ": " + rs.getString(3) + "\n";
}
tv.setText(result);
}
catch(Exception e) {
e.printStackTrace();
tv.setText(e.toString());
}
return response;
}
@Override
protected void onPostExecute(String result) {
tv.setText(result);
}
}
public void Connect() {
Connect task = new Connect();
task.execute();
}
在第80行,即行:
Connection con = DriverManager.getConnection(url, user, pass);
但我不知道为什么。 我不会忘记互联网许可 我认为连接器库有问题。