2017-03-11 27 views
0

這是我的連接類連接到服務器無法訪問在蔚藍的SQL表從機器人工作室

public class ConnectionClass { 

    @SuppressLint("NewApi") 
    public static Connection CONN() { 
     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() 
       .permitAll().build(); 
     StrictMode.setThreadPolicy(policy); 
     Connection conn = null; 
     String ConnURL = null; 
     try { 


      Class.forName("net.sourceforge.jtds.jdbc.Driver"); 
      conn = DriverManager.getConnection("jdbc:jtds:sqlserver://jazzitup.database.windows.net:1433;database=jazzitup.db;user=xxxxxxxx;password=xxxxxxxx;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30"); 
      System.out.println("AZURE:"+conn); 

     } catch (SQLException se) { 
      Log.e("ERRO", se.getMessage()); 
     } catch (ClassNotFoundException e) { 
      Log.e("ERRO", e.getMessage()); 
     } catch (Exception e) { 
      Log.e("ERRO", e.getMessage()); 
     } 
     return conn; 
    } 

} 

這個我叫CONN方法後,連接被越來越建立。 但是當我嘗試執行插入opertion:

  Connection con = ConnectionClass.CONN(); 
      String query = "insert into user_table values ('" + profile.getId() + "','" + profile.getName() + "','" + profile.getProfilePictureUri(200,200).toString() + "')"; 
      PreparedStatement preparedStatement = con.prepareStatement(query); 

       preparedStatement.executeUpdate(); 

我得到SQLEXCEPTION「USER_TABLE」是無效的對象。這是爲什麼發生? user_table exists in database and executes query in SQL Server Object Explorer

+0

你有任何更新? –

回答

0

我在您的網站上覆制了您的問題。搜索後,我發現有來自jTDS FAQs聲明,

的URL格式爲JTDS是:

jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;...]] 

正如你可以看到,從URL不同the connection URL of Microsoft JDBC Driver for SQL Server。因此,數據庫沒有正確指定,所以會引發你的問題。你可以改變你的連接字符串爲這樣的:

jdbc:jtds:sqlserver://jazzitup.database.windows.net:1433/jazzitup.db;user=xxxxxxxx;password=xxxxxxxx;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30 

我測試了它,它應該工作。