尝试将android连接到mysql时出错

时间:2016-01-20 22:34:09

标签: android mysql eclipse

我有这个问题,当我执行mi android app并尝试使用xamp将我的应用程序连接到mysql数据库时。

使用此代码

MAKEINTRESOURCE(1234)

当我执行应用程序时,我毫无理由地得到了这个错误,甚至还有版本5.181.30,所以我不知道该怎么做:

    package com.example.on_target;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
    EditText user,pass;
    Button btn_login;
    Connection conexionMySQL=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        user=(EditText)findViewById(R.id.etUser);
        pass=(EditText)findViewById(R.id.etPassword);
        btn_login=(Button)findViewById(R.id.button1);       
        btn_login.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) 
              {
                 try
                     {
                     Class.forName("com.mysql.jdbc.Driver").newInstance();
                    conexionMySQL = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/android_test?connectTimeout=3000"
                            ,"root","");
                    Log.i("Conexion","Conexion pasable");
                      String usuario=user.getText().toString();
                      String contrasena=pass.getText().toString();                    
                      Statement st = conexionMySQL.createStatement();
                      String QSLEjecutar = "select count(*) from user where user_name='"+usuario+"' and user_password='"+contrasena+"'";                                                              
                      ResultSet rs = st.executeQuery(QSLEjecutar);                                                
                      //número de columnas (campos) de la consula SQL                                

                      //mostramos el resultado
                      while (rs.next()) 
                      {                           
                             int h=rs.getInt(1);
                             if(h==1){
                                 Intent intento=new Intent(getApplicationContext(),Welcome.class);
                                 startActivity(intento);
                                 Toast.makeText(getApplicationContext(), R.string.correct,Toast.LENGTH_LONG).show();
                             }else{
                                 Toast.makeText(getApplicationContext(), R.string.incorrect,Toast.LENGTH_LONG).show();
                             }
                          }                                                                                                                 
                 }                             
                  catch (Exception e) 
                  {  
                      Log.d("WTF", e.getMessage());
                  } 
              }
            }); 
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        switch(id){
        case R.id.exit:
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }


}

0 个答案:

没有答案