简体   繁体   中英

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. 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

These are my codes.

public 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

Looks like you are getting rejected using port 54015. Is that the port the SQL Server is listening to for JDBC connections? 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM