I am trying to do some basic ResultSet to JSONArray conversion.
The code in question is the following:
ResultSetMetaData rsmd = rs.getMetaData();
JSONObject obj = new JSONObject();
String column_name = rsmd.getColumnClassName(1);
if(rsmd.getColumType(i) == java.sql.Types.Integer) {
obj.put(column_name, rs.getInt(column_name));
}
When I publish the code to the web-server and hit the page, it throws the following error:
java.sql.SQLException: Column 'java.lang.Integer' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1073)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2571)
at com.sun.gjc.spi.base.ResultSetWrapper.getInt(ResultSetWrapper.java:482)
at com.pododdle.util.ToJSON.toJSONArray(ToJSON.java:58)
atcom.pododdle.restful.resources.CategoryResource.returnCategories(CategoryResource.java:44)
Which is kinda crazy since it is complaining it can't find java.lang.Integer - a core java class!!!!
It also fails when I use the string equivalent and says it can't find java.lang.String either.
Please help. I am starting to lose my mind.
PS I don't know if this is relevant, but Maven was not automatically updating any new dependencies I wanted, so I added them manually. I don't know if this points to a greater malady in my installation - which is pretty fresh - only got eclipse et al installed yesterday on my new machine.
You are using rsmd.getColumnClassName(1)
as a column name. Now obviously the method ResultSetMetaData.getColumnClassName
returns the name of the class for that column. In your case, this column stores an integer value, so java.lang.Integer
is returned. Try to use ResultSetMetaData.getColumnName
instead to get the name of the column.