sql连接错误 - 阻止我从mysql中获取'SELECT'数据

时间:2013-12-23 12:54:36

标签: java android mysql sql

我正在尝试12小时从我的数据库中选择数据,但我不能。

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;
}

1 个答案:

答案 0 :(得分:0)

第一个函数的错误表明您正在使用JNDI命名资源来获取连接,而不是来自DriverManager的连接。

您确定该设备可以看到该主机和端口吗?设备是否有权连接? MySQL数据库中的GRANT是什么样的?

从类别表中获取名称的方法也不好。您不会关闭finally块中的任何资源。你应该。

那些// end of while// end of if条评论令人发指。他们不添加信息,只是杂乱无章。从你的代码中删除它们。