简体   繁体   English

Android Studio连接SQL数据库

[英]Android Studio connecting to SQL Database

I am trying to connect Android studio app to SQL server (Heidi SQL) I have the jtds jars (jtds-1.2.7.jar) file inside the lib and added the dependency.我正在尝试将 Android 工作室应用程序连接到 SQL 服务器(Heidi SQL)我在 lib 中有 jtds jars(jtds-1.2.7.jar)文件并添加了依赖项。 It still doesnt read the data and show the result from the database and I have this error:它仍然没有读取数据并显示数据库的结果,我有这个错误:

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

These are my codes.这些是我的代码。

public class ConnectionHelper {公共 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 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

Looks like you are getting rejected using port 54015. Is that the port the SQL Server is listening to for JDBC connections?看起来您使用端口 54015 被拒绝。这是 SQL 服务器正在侦听 JDBC 连接的端口吗? If not, you may need to append the port# to ConnectionClass.ip ie 127.0.0.1:[port number goes here] aka 127.0.0.1:12345如果没有,您可能需要 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