我有我想從我的Android設備連接到遠程MySQL服務器,我測試過上一個普通的Java控制檯應用程序代碼和它的作品完美的罰款MySQL的使用Java而不是Android的
但是當我在Android模擬器上運行它會拋出SQLException:沒有合適的驅動程序。
代碼是一樣的,MySQL的細節是一樣的,我使用了相同的兩個人的mysql jar,我真的很無能。
的Android代碼:
public class MySQL_handler {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url1,user,password;
Thread thread;
Runnable runnable;
String data = "";
public MySQL_handler() {
user = "xx";
password = "xx";
url1 = "xx";
}
public String test(){
final CountDownLatch latch = new CountDownLatch(1);
runnable = new Runnable() {
@Override
public void run() {
try
{
Log.v("S", url1);
Log.v("S", user);
Log.v("S", password);
con = DriverManager.getConnection(url1, user, password);
st = con.createStatement();
rs = st.executeQuery("SELECT CompName FROM Servers WHERE HostIP = '10.0.0.4'");
if (rs.next())
{
Log.v("sqlver",""+ rs.getString(1));
data = rs.getString(1);
}
else{
Log.v("sqlver","err");
}
}
catch (SQLException ex)
{
Log.v("SQLEX", ".."+ex);
}
finally {
try
{
if (rs != null)
{
rs.close();
}
if (st != null)
{
st.close();
}
if (con != null)
{
con.close();
}
latch.countDown();
}
catch (SQLException ex)
{
Log.v("SQLEX", "...");
latch.countDown();
}
}
}
};
thread = new Thread(runnable);
thread.start();
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return data;
}
}
請檢查您的JAR庫中是否存在用於此目的的正確路徑(它必須位於項目文件夾內) – nKn