我正在开发Android应用程序以连接SQL Server 2008,这是我的源代码 DBConn.java
public class DBConn {
private static Connection conn = null ;
private static String DRIVER = "net.sourceforge.jtds.jdbc.Driver";
private static String DB_NAME = "TestDB" ;
private static String DB_USER = "sa" ;
private static String DB_PASSWORD = "sa" ;
public boolean conSqlServer() {
Log.d("ERR","start connect SQL SERVER") ;
try {
Class.forName(DRIVER).newInstance();
String connString = "jdbc:jtds:sqlserver://192.168.1.100:1433/TestDB; instance=SQLEXPRESS; user=sa;password=sa";
conn = DriverManager.getConnection(connString);
Log.d("SUCCESS","Connection successful ");
return true;
}
catch (SQLException e) {
Log.d("ERR","ERROR CONNECTION 1 = " + e.getMessage());
e.printStackTrace();
return false ;
}
catch (Exception ex ) {
Log.d("ERR","ERROR CONNECTION 2 = " + ex.getMessage());
ex.printStackTrace();
return false ;
}
}
}
我从MainActivity.java中调用它
public class MainActivity extends ActionBarActivity {
....
....
DBConn dbconn = new DBConn();
dbconn.conSqlServer() ;
...
}
的AndroidManifest.xml
<manifest>
.....
<uses-permission android:name="android.permission.INTERNET" />
.....
</manifest>
但是我得到了这样的错误
java.sql.SQLException: Network error IOException: socket failed: EACCES (Permission denied)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:436)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at java.sql.DriverManager.getConnection(DriverManager.java:179)
at java.sql.DriverManager.getConnection(DriverManager.java:213)
at com.noh.connectdb.app.core.DBConn.conSqlServer(DBConn.java:35)
at com.noh.connectdb.app.MainActivity.onCreate(MainActivity.java:20)
....
....
任何人都可以帮助我吗?