2013-12-23 23 views
0

我想12小時現在從我的數據庫中選擇數據,但我不能。sql連接錯誤 - 阻止我從'SELECT'數據從mysql

INSERT正常工作。只是選擇不工作。

當我運行connect()函數我我得到很多的誤區:

 public void connect() { 
     String dbUrl = "jdbc:mysql://*****.heliohost.org:3306/*****"; 
     try 
     { 
      Class.forName("com.mysql.jdbc.Driver"); 
      connection = DriverManager.getConnection(dbUrl,"*****","****"); 
      return;//the debugger never succeed to reach this line 

     } catch (Exception e) { 
      e.printStackTrace(); 

     } 
     } 

的錯誤,我從上面得到connect()函數:

12-23 16:22:54.460: W/dalvikvm(7473): VFY: unable to find class referenced in signature (Ljavax/naming/Reference;) 
12-23 16:22:54.470: I/dalvikvm(7473): Could not find method javax.naming.Reference.get, referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.initializeFrom 
12-23 16:22:54.470: W/dalvikvm(7473): VFY: unable to resolve virtual method 14440: Ljavax/naming/Reference;.get (Ljava/lang/String;)Ljavax/naming/RefAddr; 
12-23 16:22:54.470: D/dalvikvm(7473): VFY: replacing opcode 0x6e at 0x0004 
12-23 16:22:54.491: W/dalvikvm(7473): VFY: unable to find class referenced in signature (Ljavax/naming/Reference;) 
12-23 16:22:54.491: E/dalvikvm(7473): Could not find class 'javax.naming.StringRefAddr', referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.storeTo 
12-23 16:22:54.491: W/dalvikvm(7473): VFY: unable to resolve new-instance 1365 (Ljavax/naming/StringRefAddr;) in Lcom/mysql/jdbc/ConnectionPropertiesImpl$ConnectionProperty; 
12-23 16:22:54.491: D/dalvikvm(7473): VFY: replacing opcode 0x22 at 0x0006 

下一個功能下降「String tem = result.getString(」name「)」:

public List<String> selectCategories() 
{ 
    List<String> listCS = new ArrayList<String>(); 
    try 
    { 
      Statement statement = connection.createStatement(); 
      statement.execute("select name from categories"); 
      ResultSet result=statement.getResultSet(); 

      if(result!=null) 
      { 
       while(result.next()); 
       { 
        String tem = result.getString("name"); 
        listCS.add(tem);          

       }//end of while 
      }//end of if 

    }//end of try 
    catch(java.sql.SQLException e) 
    { 
     e.printStackTrace(); 
    } 
    return listCS; 
} 

回答

0

來自第一個函數的錯誤含義st你使用的是一個名爲JNDI的資源來獲取連接,而不是來自DriverManager的連接。

您確定設備可以看到該主機和端口嗎?設備是否具有連接權限? MySQL數據庫中的GRANT是什麼樣的?

您從類別表中獲取名稱的方法也不好。你不會在finally塊中關閉任何資源。你應該。

那些// end of while// end of if評論是可惡的。他們不添加信息,只是混亂。從代碼中刪除這些內容。

+0

我做了'GRANT ALL'給我的用戶,我正在連接到數據庫。我會添加接近資源。但這並不能解決我的錯誤。 – CmTiger

+0

這些堆棧跟蹤不是您從DriverManager連接看到的。你可以在沒有Android的情況下單獨測試該類嗎?我建議你這樣做。 – duffymo

+0

我做了你所說的 - 我創造了新的項目,並完美地工作。你知道我怎麼解決這個問題? /: – CmTiger