在 Android Studio 中直接连接到 Microsoft SQL Server 2012
Direct Connect to Microsoft SQL Server 2012 in Android Studio
我已经使用 SQL 服务器 2012 创建了一个数据库,我想直接连接并从 android 在 android studio 中开发的应用程序访问它。
我将 jtds-1.3.1.java 导入项目,但未连接。
我的代码是:
public void query2()
{
Log.i("Android"," MySQL Connect Example.");
Connection conn = null;
try {
String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
String connString = "jdbc:jtds:sqlserver://ip_address:1433/DBname;";
String username = "***";
String password = "****";
conn = DriverManager.getConnection(connString,username,password);
Log.w("Connection","open");
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("select * from t1");
while(reset.next()){
txtData.setText(reset.getString(1));
}
conn.close();
} catch (Exception e)
{
Log.w("Error connection","" + e.getMessage());
txtData.setText("Error in Connection");
}
}
- 在 android Studio
中添加 EasyWSDl 插件
- 在 main/java
中创建一个包
- 右击包selectEseayWSDL-添加网络服务
- 把 asmx url
我已经使用 SQL 服务器 2012 创建了一个数据库,我想直接连接并从 android 在 android studio 中开发的应用程序访问它。
我将 jtds-1.3.1.java 导入项目,但未连接。
我的代码是:
public void query2()
{
Log.i("Android"," MySQL Connect Example.");
Connection conn = null;
try {
String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
String connString = "jdbc:jtds:sqlserver://ip_address:1433/DBname;";
String username = "***";
String password = "****";
conn = DriverManager.getConnection(connString,username,password);
Log.w("Connection","open");
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("select * from t1");
while(reset.next()){
txtData.setText(reset.getString(1));
}
conn.close();
} catch (Exception e)
{
Log.w("Error connection","" + e.getMessage());
txtData.setText("Error in Connection");
}
}
- 在 android Studio 中添加 EasyWSDl 插件
- 在 main/java 中创建一个包
- 右击包selectEseayWSDL-添加网络服务
- 把 asmx url