my dog learned polymorphism*
The moose likes Java in General and the fly likes Couldn't retreive a String from the result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Couldn Watch "Couldn New topic
Author

Couldn't retreive a String from the result set

elizabeth thomas
Greenhorn

Joined: May 12, 2003
Posts: 7
Hi,
I am trying to execute a simple query and output the result to swing components. it retrieves correctly for the numeric columns in the query. However, when use rs.getString(cloumn) statement, it gives me error "java.sql.SQLException: [Oracle][ODBC]Invalid column number <2>." I tried replacing <2> and <3> with the actual column name, but no luck.
Please help me
CODE] void FindName_actionPerformed(ActionEvent e) {
try
{
if (!fields.WorkID.getText().equals(""))
{
Statement stmt = connection.createStatement();
String query = "SELECT Work_ID, Work_Requested, Work_Requested_By, Organization_Element_ID " +
"FROM Work Where Work_ID = " + fields.WorkID.getText();
output.append ("\n Sending query: " + query + "\n");
ResultSet rs = stmt.executeQuery(query);
display (rs);
output.append ("\n Query successful");
}
else
{
fields.WorkID.setText ("Enter name here then press Find");
}
}
catch (SQLException sqle)
{
sqle.printStackTrace();
output.append(sqle.toString());
}
}
public void display (ResultSet rs)
{
try
{
rs.next();
int work_id = rs.getInt("Work_ID");
int org_id = rs.getInt("Organization_Element_ID");
if (work_id != 0)
{
fields.WorkID.setText (String.valueOf(work_id));
fields.OrganizationID.setText(String.valueOf(org_id));
fields.WorkRequested.setText(rs.getString(2));
fields.WorkRequestedBy.setText(rs.getString(3));
}
else
output.append ("\n No record found");
}
catch (SQLException sqle)
{
sqle.printStackTrace();
output.append(sqle.toString());
}
}
}[ [/CODE]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Your problem is not necessarily in your code( well actually it is, but I'll explain ). You've decided to use the Oracle ODBC-JDBC drivers, which are to say the least "finicky"...otherwise known as "crappy". They can get the job done, but have exponentially more limitations than that of its type 4 rival the "thin" drivers. One of the limitations of most ODBC drivers is that you must retrieve column values in order that they appear in your query. So in your case, you should reword your query to start with
"SELECT Work_ID, Organization_Element_ID, Work_Requested, Work_Requested_By..."
because it matches the order in which you retrieve the values in your code. This is not a limitation of the "thin" drivers ( or OCI for that matter ) and your code would work fine with them.
Can't see anything else that is "Exception worthy" in your code,
Jamie
elizabeth thomas
Greenhorn

Joined: May 12, 2003
Posts: 7
Thanks a lot Jamie.
It solved my problem.
Could you please give me an example on how to use an Oracle thin driver? I tried the follwing, but didn't work. Gives me an error : "CLassNotFoundException"
String Driver = "oracle.jdbc.driver.OracleDriver";
String URL = "jdbc racle:thin@hostID ort:service";
try {
Class.forName (Driver);
connection = DriverManager.getConnection (URL, "scott", "tiger");
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Couldn't retreive a String from the result set
 
Similar Threads
refresh table doesn't work
Invaild Cursor State
Invalid Coursor Name...
Database access, potential threading problem?
isNew() method