1

我试图从数据库中检索电子邮件地址,但没有成功。我的代码如下:

主要的:

System.out.println(PortfolioData.getEmails(58));  //So Far Returning null

投资组合数据:

public static String[] getEmails(int i){    
    DebugMessage.M("Retrieving Email Records for Person Key Number: " + i);
    eq.query("SELECT EmailAddresses"
            + " FROM Emails as E"
            + " JOIN People AS P ON E.PersonKey = P.PersonKey"
            + " WHERE P.PersonKey = ?",i);
    return (String[])eq.getOnceMultipleRows("EmailAddresses");
}

DBEasyQuery:

public Object getOnceMultipleRows(String label){
    if(next()){
        try {   
            Array a = rs.getArray(label);
            String[] x = (String[])a.getArray();
            smartClose();
            return x;
            //return rs.getArray(label).getArray();
        } catch (SQLException e) {
            DebugMessage.E("getOnceMultipleRows() Failed on Query: " + queryExecuted());
            DebugMessage.E("getOnceMultiple() Failed on Label: " + label );
            notExecuted(e);
        }   
    }
    smartClose();
    return null;
}

这是我的日志文件和错误:

MESSAGE:   Retrieving Person Records for Person Key Number: 58
MESSAGE:   SharedConnection dziemba created
SQLQUERY:    SELECT AlphaID, FirstName, LastName, Street, City, State, Zip, Country, AcctType, SecID FROM People AS P JOIN Addresses AS A ON P.PersonKey = A.PersonKey LEFT JOIN Role AS R ON P.PersonKey = R.PersonKey WHERE P.PersonKey = 58
MESSAGE:   Retrieving Email Records for Person Key Number: 58
SQLQUERY:    SELECT EmailAddresses FROM Emails as E JOIN People AS P ON E.PersonKey = P.PersonKey WHERE P.PersonKey = 58
ERROR:   getOnceMultipleRows() Failed on Query:  SELECT EmailAddresses FROM Emails as E JOIN People AS P ON E.PersonKey = P.PersonKey WHERE P.PersonKey = 58
ERROR:   getOnceMultiple() Failed on Label: EmailAddresses
ERROR:   
 The Following Query Was NOT Executed:
 SELECT EmailAddresses FROM Emails as E JOIN People AS P ON E.PersonKey = P.PersonKey WHERE P.PersonKey = 58
 Stack Trace:
ERROR:   sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
ERROR:   sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
ERROR:   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
ERROR:   java.lang.reflect.Constructor.newInstance(Unknown Source)
ERROR:   java.lang.Class.newInstance(Unknown Source)
ERROR:   com.mysql.jdbc.SQLError.notImplemented(SQLError.java:1334)
ERROR:   com.mysql.jdbc.ResultSetImpl.getArray(ResultSetImpl.java:1230)
ERROR:   com.mysql.jdbc.ResultSetImpl.getArray(ResultSetImpl.java:1247)
ERROR:   unl.cse.DBEasyQuery.getOnceMultipleRows(DBEasyQuery.java:218)
ERROR:   unl.cse.PortfolioData.getEmails(PortfolioData.java:136)
ERROR:   unl.cse.Main.main(Main.java:44)
ERROR:   

Kayaman 评论说我的错误日志没有显示实际的异常。所以我删除了我的错误记录和捕获。这是我现在在终端中得到的内容:

[Ljava.lang.String;@59966240
java.sql.SQLFeatureNotSupportedException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at com.mysql.jdbc.SQLError.notImplemented(SQLError.java:1334)
    at com.mysql.jdbc.ResultSetImpl.getArray(ResultSetImpl.java:1230)
    at com.mysql.jdbc.ResultSetImpl.getArray(ResultSetImpl.java:1247)
    at unl.cse.DBEasyQuery.getOnceMultipleRows(DBEasyQuery.java:220)
    at unl.cse.PortfolioData.getEmails(PortfolioData.java:136)
    at unl.cse.Main.main(Main.java:44)
Exception in thread "main" java.lang.NullPointerException
    at unl.cse.DBEasyQuery.getOnceMultipleRows(DBEasyQuery.java:227)
    at unl.cse.PortfolioData.getEmails(PortfolioData.java:136)
    at unl.cse.Main.main(Main.java:44)

查询本身在 MySQL Workbench 中执行良好: 在此处输入图像描述

DBEasyQuery 的一些附加支持代码可以在下图中找到。我从帖子中删除了它,因为它使帖子很长:http: //i.stack.imgur.com/WZDkL.png

我认为它没有错误,因为它适用于我可以扔给它的所有其他东西:

4

1 回答 1

1

问题出在 JDBC 驱动程序中。并非所有驱动程序都支持所有功能,您使用的驱动程序也不支持此功能。

解决方案:找到支持该功能的不同驱动程序(如果存在)。

编辑:在驾驶员方面看起来不太好。您可能必须以不同的方式执行查询。

编辑#2:MySQL 似乎不支持 ARRAY 类型,因此您需要以老式方式做事。

于 2013-11-09T08:10:42.750 回答