从Java SQL阵列获取的ResultSet失败 [英] Java get ResultSet from SQL Array is Failing

查看:215
本文介绍了从Java SQL阵列获取的ResultSet失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Im trying to retrieve email addresses from a database but am not having success. My Code is as Follows:

主营:

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

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:

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评论说我的错误日志不显示实际例外。所以,我已经打消了我的错误日志记录和捕捉。这里是什么我现在在终端获得:

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)

查询本身的MySQL工作台内执行罚款:

The query itself executes fine inside MySQL Workbench:

有些DBEasyQuery的额外支持code可以在下面的图片中找到。我从后显示,因为它使后很长删除它: HTTP://i.stack .imgur.com / WZDkL.png

Some of the additional supporting code of DBEasyQuery can be found in the below picture. I removed it from showing in the post since it makes the post really long: 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:

推荐答案

问题是在JDBC驱动程序。并非所有的驱动程序支持所有功能,并且您正在使用的驱动程序不支持这一点。

The problem is in the JDBC driver. 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).

编辑:
它看起来并不驾驶员侧太好。您可能需要不同的执行查询。

It doesn't look too good on the driver side. You might have to perform your queries differently.

编辑#2:似乎 MySQL不支持数组类型所以你需要做的事情的老式方法。

EDIT #2: It seems that MySQL doesn't support the ARRAY type so you will need to do things in the old fashioned way.

这篇关于从Java SQL阵列获取的ResultSet失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆