簡體   English   中英

Android Studio連接SQL數據庫

[英]Android Studio connecting to SQL Database

我正在嘗試將 Android 工作室應用程序連接到 SQL 服務器(Heidi SQL)我在 lib 中有 jtds jars(jtds-1.2.7.jar)文件並添加了依賴項。 它仍然沒有讀取數據並顯示數據庫的結果,我有這個錯誤:

E/Error:.net.sourceforge.jtds.jdbc.Driver enter image description here

這些是我的代碼。

公共 class ConnectionHelper {

 Connection con; String uname, pass, ip, port, database; @SuppressLint("NewApi") public Connection connectionClass() { ip = "127.0.0.1"; database = "eat"; uname = "root"; pass = "pass"; StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); Connection connection = null; String ConnectionURL = null; try{ Class.forName(.net.sourceforge.jtds.jdbc.Driver"); ConnectionURL = "jdbc:jtds:mysqlserver://" + ip + "/" + database + ";user=" + uname + ";password=" + pass +";"; connection = DriverManager.getConnection(ConnectionURL); } catch (Exception ex){ Log.e("Error", ex.getMessage()); } return connection; } }

The problem is IP address 127.0.0.1 is the default IP address of the localhost of the device, You need to change it with IP address of the device running the Apache Server

看起來您使用端口 54015 被拒絕。這是 SQL 服務器正在偵聽 JDBC 連接的端口嗎? 如果沒有,您可能需要 append 端口號到 ConnectionClass.ip 即 127.0.0.1:[端口號在這里] aka 127.0.0.1:12345

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM