2016-07-30 37 views
0

我连接的java文件包含:机器人 - SQL Server的 - 连接null或者没有合适的司机发现

try { 
    Log.i("Login", "Establishing Connection..."); 
    // SET CONNECTIONSTRING 
    Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance(); 
    Log.i("JDBC","found"); 
    Connection DbConn = DriverManager.getConnection("<connection_string>"); 

    Log.i("Login","Connected"); 
    Statement stmt = DbConn.createStatement(); 
    ResultSet insert = stmt.executeQuery("insert into UserLogin(username, password) values (admin, admin);"); 
    ResultSet reset = stmt.executeQuery(" select * from UserLogin "); 

    Toast.makeText(this, reset.getString(1), Toast.LENGTH_SHORT).show(); 

    DbConn.close(); 

    // go to newsfeed 
} catch (Exception e) { 
    Log.e("Error connection","" + e.getMessage()); 
} 

当我的连接字符串包含:
JDBC:JTDS:SQLSERVER://,我得到错误连接:空,并且当它
的jdbc:SQLSERVER://,               我得到连接错误:找不到合适的驱动程序

我试图连接Android与Azure SQL数据库

我见过Question1,Question2,Question3,Question4.   没有答案。

+1

建议在Android客户端和数据库服务器之间添加另一部分。像PHP,ASP.NET,Python等等。考虑一下攻击者逆向工程你的Android客户端,然后他可以直接访问你的数据库。 –

回答

1

@NiravMadariya,与JTDS JDBC连接字符串shoule是jdbc:jtds:sqlserver://<server>:<port>/<database>,请参见常见问题解答JTDS包括URL formatNo suitable driver异常的原因。

请注意,如果您使用Auzre SQL DB的JTDS JDBC驱动程序,那么您需要将ssl=require添加到连接字符串的URL中,就像这个jdbc:jtds:sqlserver://<server>:<port>/<database>?ssl=require一样。

同时,对于SQL Server使用Microsoft JDBC驱动程序是Azure SQL DB的推荐方式,请参阅https://azure.microsoft.com/en-us/documentation/articles/sql-database-develop-java-simple/

相关问题