简体   繁体   English

Java从SQL数组获取ResultSet失败

[英]Java get ResultSet from SQL Array is Failing

Im trying to retrieve email addresses from a database but am not having success. 我试图从数据库中检索电子邮件地址,但没有成功。 My Code is as Follows: 我的代码如下:

Main: 主要:

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

PortfolioData: PortfolioData:

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

Here is my log file and errors: 这是我的日志文件和错误:

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 commented that my error log wasn't showing the actual exception. 卡亚曼评论说我的错误日志没有显示实际的异常。 So I've removed my error logging and catching. 因此,我已经删除了错误记录和捕获功能。 Here is what I'm now getting in the terminal: 这是我现在要进入终端的内容:

[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)

The query itself executes fine inside MySQL Workbench: 查询本身在MySQL Workbench内可以正常执行: 在此处输入图片说明

Some of the additional supporting code of DBEasyQuery can be found in the below picture. 下图提供了DBEasyQuery的一些其他支持代码。 I removed it from showing in the post since it makes the post really long: http://i.stack.imgur.com/WZDkL.png 我将其从帖子中显示中删除了,因为它使帖子变得很长: http : //i.stack.imgur.com/WZDkL.png

I don't think there is an error in it since it works fine for everything else I can throw at it: 我认为其中没有错误,因为它可以很好地解决所有其他问题:

The problem is in the JDBC driver. 问题出在JDBC驱动程序中。 Not all drivers support all features, and the driver you're using doesn't support this. 并非所有驱动程序都支持所有功能,并且您使用的驱动程序不支持此功能。

Solutions: find a different driver that supports the feature (if one exists). 解决方案:找到支持该功能的其他驱动程序(如果存在)。

EDIT: It doesn't look too good on the driver side. 编辑:在驱动程序方面看起来不太好。 You might have to perform your queries differently. 您可能必须以不同的方式执行查询。

EDIT #2: It seems that MySQL doesn't support the ARRAY type so you will need to do things in the old fashioned way. 编辑#2:看来MySQL不支持ARRAY类型,因此您将需要以老式的方式进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM