Questions tagged [resultset]

A result set is a set of rows from a database, which is usually generated by executing a statement that queries the database. A resultSet object maintains a cursor pointing to its current row of data.

A result set is a set of rows from a database, which is usually generated by executing a statement that queries the database. A resultSet object maintains a cursor pointing to its current row of data.

2543 questions
31
votes
3 answers

How do you get values from all columns using ResultSet.getBinaryStream() in jdbc?

How do I to write an entire table to a flat file (text file) using jdbc? So far I've attempted the following: Statement statement = connection.createStatement(); ResultSet result = statement.executeQuery("SELECT * FROM tablename"); …
Harish Vangavolu
  • 965
  • 2
  • 12
  • 27
30
votes
9 answers

ResultSet: Exception: set type is TYPE_FORWARD_ONLY -- why?

I have very simple code: pstat=con.prepareStatement("select typeid from users where username=? and password=?"); pstat.setString(1, username); pstat.setString(2, password); rs=pstat.executeQuery(); int rowCount=0; while(rs.next()) { …
sAaNu
  • 1,428
  • 7
  • 21
  • 46
30
votes
5 answers

How to check that a ResultSet contains a specifically named field?

Having rs, an instance of java.sql.ResultSet, how to check that it contains a column named "theColumn"?
Ivan
  • 63,011
  • 101
  • 250
  • 382
30
votes
5 answers

How to judge whether selected result is empty or not with jQuery?

$("#experiences tr") For the above one,how to judge if it's empty or not? I thought its boolean value should be false,but seems not.
omg
  • 136,412
  • 142
  • 288
  • 348
28
votes
1 answer

getColumnLabel vs. getColumnName

What is the difference between ResultSetMetaData.getColumnLabel and ResultSetMetaData.getColumnName? Label: Gets the designated column's suggested title for use in printouts and displays. Name: Get the designated column's name. Does anyone know how…
sova
  • 5,468
  • 10
  • 40
  • 48
27
votes
3 answers

JDBC ResultSet getDate losing precision

I am losing precision in my ResultSet.getDate(x) calls. Basically: rs = ps.executeQuery(); rs.getDate("MODIFIED"); is returning dates truncated to the day where MODIFIED is an Oracle TIMESTAMP field of default precision. I think there may be some…
orbfish
  • 7,381
  • 14
  • 58
  • 75
27
votes
2 answers

Iterating over ResultSet and adding its value in an ArrayList

I am iterating over an ResultSet and trying to copy its values in an ArrayList. The problem is that its traversing only once. But using resultset.getString("Col 1") to resultset.getString('Col n") is showing all entries of all columns. Below is the…
R11G
  • 1,941
  • 8
  • 26
  • 37
26
votes
3 answers

Execute anonymous pl/sql block and get resultset in java

I would like to execute the anonymous PL/SQL and need to get the resultset object. I got the code which can be done by using cursors inside the PL/SQL block. But the PL/SQL block itself will come from the database as text. So I can't edit that…
RajKP
  • 263
  • 1
  • 3
  • 6
26
votes
7 answers

How to check if resultset has one row or more?

How to check if resultset has one row or more with JDBC?
TopCoder
  • 4,206
  • 19
  • 52
  • 64
25
votes
2 answers

Getting java.sql.SQLException: Operation not allowed after ResultSet closed

When I execute the following code, I get an exception. I think it is because I'm preparing in new statement with he same connection object. How should I rewrite this so that I can create a prepared statement AND get to use rs2? Do I have to create a…
samxli
  • 1,536
  • 5
  • 17
  • 28
24
votes
6 answers

Easy way to fill up ResultSet with data

I want to mock a ResultSet. Seriously. I'm refactoring one big complicated piece of code which is parsing data from ResultSet, and I want my code to behave identically. So, I need to write a unit test for the piece being refactored to be able to…
DiaWorD
  • 963
  • 2
  • 11
  • 10
24
votes
15 answers

Create a comma-separated string from a single column of an array of objects

I'm using a foreach loop to echo out some values from my database, I need to strip the last comma from the last loop if that makes sense. My loop is just simple, as below foreach($results as $result){ echo $result->name.','; } Which echos…
Cecil
  • 1,609
  • 5
  • 21
  • 26
22
votes
3 answers

rs.last() gives Invalid operation for forward only resultset : last

I am trying to get the row count of a result set by: rs.last(); int row_count = rs.getRow(); but im getting an Invalid operation for forward only resultset : last error. The result set is getting its data from an Oracle 10g database. Here is how i…
Mike
  • 2,299
  • 13
  • 49
  • 71
22
votes
2 answers

Java ResultSet, SetObject vs SetString/SetDate/etc

I'd like to know whether anyone considers using PreparedStatement.setObject for all data types as bad practice when preparing a statement. A use case for this would be a DAO with a generic executeQuery() method which can be re-used for all queries…
S.D
  • 275
  • 2
  • 10
21
votes
16 answers

JDBC returning empty result set

I'm using JDBC for very simple database connectivity. I have created my connection/statement and executed a query. I check the query object of the statement in the debugger to confirm that it is sending a proper query. I then double checked the…
dpsthree
  • 2,225
  • 4
  • 21
  • 23