2016-02-21 117 views
0

我想繪製jdbc爲Android它似乎沒有獲得任何信息。我不確定驅動程序或連接是否存在問題字符串是否可以有人請告訴我,我一直在嘗試數週。無法執行查詢使用jdbc

我的logcat給我的下面,當我嘗試運行的連接:

02-21 10:55:08.940 9513-9561/? E/dalvikvm﹕ Could not find class 'javax.naming.StringRefAddr', referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.storeTo 

02-21 11:23:28.940 19790-19877/net.azurewebsites.cosy W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljavax/naming/Reference;) 
02-21 11:23:28.940 19790-19877/net.azurewebsites.cosy I/dalvikvm﹕ Could not find method javax.naming.Reference.get, referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.initializeFrom 
02-21 11:23:28.940 19790-19877/net.azurewebsites.cosy W/dalvikvm﹕ VFY: unable to resolve virtual method 14328: Ljavax/naming/Reference;.get (Ljava/lang/String;)Ljavax/naming/RefAddr; 
02-21 11:23:28.940 19790-19877/net.azurewebsites.cosy D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0004 
02-21 11:23:28.944 19790-19877/net.azurewebsites.cosy W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljavax/naming/Reference;) 
02-21 11:23:28.948 19790-19877/net.azurewebsites.cosy E/dalvikvm﹕ Could not find class 'javax.naming.StringRefAddr', referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.storeTo 
02-21 11:23:28.948 19790-19877/net.azurewebsites.cosy W/dalvikvm﹕ VFY: unable to resolve new-instance 1453 (Ljavax/naming/StringRefAddr;) in Lcom/mysql/jdbc/ConnectionPropertiesImpl$ConnectionProperty; 
02-21 11:23:28.948 19790-19877/net.azurewebsites.cosy D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0006 
02-21 11:23:28.952 19790-19877/net.azurewebsites.cosy D/dalvikvm﹕ DexOpt: unable to opt direct call 0x37fa at 0x14 in Lcom/mysql/jdbc/ConnectionPropertiesImpl$ConnectionProperty;.storeTo 

這裏是我的連接字符串

public static final String connectionString = "jdbc:sqlserver://cosy.database.windows.net"; 
public static final String db_user = "eocribin"; 
public static final String db_pass = "Ecribin1"; 
public static final String DRIVER = "com.mysql.jdbc.Driver"; 

,這裏是我的助手類:

public class BookHelper 
{ 
    private Connection conn; 
    private String TAG = BookHelper.class.getSimpleName(); 


    public BookHelper() 
    { 
     conn = null; 

     try 
     { 
      Log.d(TAG,"attempt to connect"); 

      Class.forName(jdbc.DRIVER); 
      conn = DriverManager.getConnection(jdbc.connectionString, jdbc.db_user, jdbc.db_pass); 

     } 
     catch (SQLException e) 
     { 
      Log.d(TAG,"server broke"); 

      Log.e(TAG, e.getMessage()); 
     } 
     catch (ClassNotFoundException e) 
     { 
      Log.d(TAG,"connections fault"); 

      Log.e(TAG, e.getMessage()); 
     } 
    } 





    public ResultSet getAllDetails() 
    { 

     Log.d(TAG,"we are connected"); 
     Log.d(TAG,"starting query"); 

     String query = "select Bookname, SubjectName from books join Subjects on Subjects.SubjectID = Books.subjectID where classID = '1a'"; 
     ResultSet temp = null; 
     try 
     { 

      Statement st = conn.createStatement(); 
      ResultSet rs = st.executeQuery(query); 

      temp = rs; 

     } 
     catch(SQLException c) 
     { 
      Log.e(TAG, c.getMessage()); 

     } 

     return temp; 



    } 



} 

當我以任何方式改變連接時,我得到一個奇怪的空指針異常。

+0

注意,JDBC通常不使用在Android,因爲它不被設計爲使用通過WiFi或移動數據連接。 – CommonsWare

+0

@CommonsWare你會推薦使用PHP嗎? –

+0

我會推薦一個Web服務。無論你在PHP中實現一個還是其他的都取決於你。 – CommonsWare

回答

0

連接字符串應該是:

jdbc:mysql://<Host>:<Port>/<Database> 
+0

那只是針對mysql他可能是用sqlserver – achabahe

+0

哦,nvm然後... – Cedric

+0

@cedrickring它是一個SQL服務器,不幸的是 –