本地机器上使用Android和MySQL的通信链路故障,API 19,Android 4.4.2
我的应用程序运行正常,直到我将eclipse从开普勒升级到6月份,ADT插件从API 17升级到API 19,MySQL JDCB Java Conctor从5.1.26升级到5.1.29 现在我在尝试创建到DB的连接时遇到通信链路故障错误。不同版本之间有什么变化吗 我已经检查了很多次我的代码,但都是好的。但我也在这里复制本地机器上使用Android和MySQL的通信链路故障,API 19,Android 4.4.2,android,mysql,eclipse,Android,Mysql,Eclipse,我的应用程序运行正常,直到我将eclipse从开普勒升级到6月份,ADT插件从API 17升级到API 19,MySQL JDCB Java Conctor从5.1.26升级到5.1.29 现在我在尝试创建到DB的连接时遇到通信链路故障错误。不同版本之间有什么变化吗 我已经检查了很多次我的代码,但都是好的。但我也在这里复制 import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStat
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.example.pruebaconn.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainConn extends Activity {
private String mEmail = "";
private String mPassword = "";
private String mReserveCode = "";
// UI references.
private EditText mEmailView;
private EditText mPasswordView;
private EditText mReserveCodeView;
static String urlConMySQL = "jdbc:mysql://10.0.2.2:3306/journey_app";
static String userMySQL = "root";
static String passwordMySQL = "XXXXX"; // Password intentionally hidden
static public Connection mainConnectionMySQL;
static public Statement st;
public Context context;
private boolean userOK = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Set up the login form.
context = getApplicationContext();
mEmailView = (EditText) findViewById(R.id.login_email);
mEmailView.setText(mEmail);
mPasswordView = (EditText) findViewById(R.id.login_password);
mPasswordView.setText(mPassword);
findViewById(R.id.login_button_sign_in).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
attemptLogin();
}
});
}
public void attemptLogin() {
// Reset errors.
mEmailView.setError(null);
mPasswordView.setError(null);
// Store values at the time of the login attempt.
mEmail = mEmailView.getText().toString();
mPassword = mPasswordView.getText().toString();
userOK = validateUserPassword(mEmail, mPassword);
}
public boolean validateUserPassword (String appU, String pass) {
boolean userOK = false;
try {
userOK = userPasswordValidation(appU, pass);
} catch (Exception e) {
}
return userOK;
}
public Boolean userPasswordValidation (String user, String password) throws Exception {
Boolean userExists = false;
String sqlValidaUserPassword;
sqlValidaUserPassword = "" +
" SELECT CAST(COUNT(*) > 0 AS CHAR) USER_EXIST_FLAG " +
" FROM APP_USER " +
" WHERE APP_USER_ID = '" + user + "' " +
" AND APP_USER_PASSWORD = '" + password + "'";
try {
createConnection();
PreparedStatement ps = mainConnectionMySQL.prepareStatement(sqlValidaUserPassword);
ResultSet rs = ps.executeQuery(sqlValidaUserPassword);
while (rs.next()) {
userExists = rs.getBoolean(1);
}
rs.close();
ps.close();
} catch (Exception e) {
Toast.makeText(context, "Error " + e.getMessage(), Toast.LENGTH_SHORT).show();
throw e;
} finally {
closeConnection();
}
return userExists;
}
public void createConnection () // throws InstantiationException, IllegalAccessException, ClassNotFoundException
{
try {
Class.forName("com.mysql.jdbc.Driver");
mainConnectionMySQL = DriverManager.getConnection(urlConMySQL,userMySQL, passwordMySQL);
st = mainConnectionMySQL.createStatement();
} catch (ClassNotFoundException e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
} catch (SQLException e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
public void closeConnection ()
{
try {
if (st != null) {
mainConnectionMySQL.close();
}
if (mainConnectionMySQL != null) {
mainConnectionMySQL.close();
}
} catch (SQLException e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}开普勒至六月-?你是说朱诺对开普勒?或者你降级了?第一:在android上使用jdbc是一个非常糟糕的主意,第二:你在主线程上进行网络操作。它在3、4天前运行正常,但升级到4.4.2后,已经坏了。。。我已重新安装所有,但它不运行