1

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:

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 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: enter image description here

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: https://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:

Derek Ziemba
  • 2,467
  • 22
  • 22

1 Answers1

1

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

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.

Kayaman
  • 72,141
  • 5
  • 83
  • 121