jdbc - Java ResulSet anormally returns empty fields -
i struggling resultset presents empty fields there should values (i tested query in oracle sql dev). strange because 1 of field ("opendate" -> rs.getdate(5)) correctly fetched not other ones. here code :
public void refreshdata() { try { globals.itrackdatabase.connect(); resultset rs; rs = globals.itrackdatabase.execquery(globals.caserankingquery + " case_num = '19816641'"); // resultsetmetadata metadata = rs.getmetadata(); // int numberofcolumns = metadata.getcolumncount(); while (rs.next()) { system.out.println(rs.getstring(1)); case caseobj = new case(rs.getstring(1), rs.getstring(2), rs.getstring(3), rs.getstring(4), rs.getdate(5), rs.getstring(6), rs.getstring(7), rs.getstring(8), null, rs.getstring(9), rs.getstring(10), 0); globals.caselist.add(caseobj); } (int = 0; <= globals.caselist.size()-1; i++) { data[i][1] = globals.caselist.get(i).id; data[i][2] = globals.caselist.get(i).service; data[i][3] = globals.caselist.get(i).module; data[i][4] = globals.caselist.get(i).summary; data[i][5] = globals.caselist.get(i).opendate; data[i][6] = globals.caselist.get(i).hub; data[i][7] = globals.caselist.get(i).enduser; data[i][8] = globals.caselist.get(i).endusergroup; data[i][9] = globals.caselist.get(i).assignationdate; data[i][10] = globals.caselist.get(i).timespent; data[i][11] = globals.caselist.get(i).assignee; data[i][12] = globals.caselist.get(i).assigneebacklog; } globals.itrackdatabase.disconnect(); system.out.println(arrays.deeptostring(data)); this.firetabledatachanged(); } catch (sqlexception e) { system.out.println("query failed."); e.printstacktrace(); } }
and :
public resultset execquery(string query) { try { statement stmt = connection.createstatement(); system.out.println("executing: " + query); return stmt.executequery(query); } catch (sqlexception e) { system.out.println("query failed."); e.printstacktrace(); return null; } }
the case object construcor :
public case(string id, string service, string module, string summary, date opendate, string hub, string enduser, string endusergroup, date assignationdate, string timespent, string assignee, int assigneebacklog) { this.id = id; this.service = service; this.module = module; this.summary = summary; this.opendate = opendate; this.hub = hub; this.enduser = enduser; this.endusergroup = endusergroup; this.endusergroup = endusergroup; this.assignationdate = assignationdate; this.timespent = timespent; this.assignee = assignee; this.assigneebacklog = assigneebacklog; }
the query :
select case_num, service, module, summary, open_date, case_hub, end_user, end_user_site, end_user_dept, time_spent, assignee case case_num = '19816641';
my console debug :
-------- oracle jdbc connection testing ------ connected itrack database. executing: select case_num, service, module, summary, open_date, case_hub, end_user, end_user_site, end_user_dept, time_spent, assignee case case_num = '19816641' [[null, , , null, , 2015-07-19, , , , null, , , 0]]
thanks help.
okay, found : had use ascii stream getter resultset , created following function change string :
public string getstringfrominputstream(inputstream is) { inputstreamreader in = new inputstreamreader(is); string str = ""; try { while (in.ready()) { str = str + (char) in.read(); } return str; } catch (ioexception e) { e.printstacktrace(); return null; }
the call way :
getstringfrominputstream(rs.getasciistream(1))
hope helps.
Comments
Post a Comment