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
54
votes
1 answer

Trying to get the average of a count resultset

I have the following SQL:(bitemp) SELECT COUNT (*) AS Count FROM Table T WHERE (T.Update_time = (SELECT MAX (B.Update_time ) FROM Table B WHERE (B.Id = T.Id)) GROUP BY T.Grouping now I am getting a resultset…
Xavjer
  • 8,838
  • 2
  • 22
  • 42
54
votes
4 answers

JDBC ResultSet: I need a getDateTime, but there is only getDate and getTimeStamp

I would like to get the DATETIME column from an Oracle DB Table with JDBC. Here is my code: int columnType = rsmd.getColumnType(i); if(columnType == Types.DATE) { Date aDate = rs.getDate(i); valueToInsert = aDate.toString(); } else…
Tim
  • 3,910
  • 8
  • 45
  • 80
53
votes
8 answers

JDBC ResultSet get columns with table alias

Imagine I have a query like SELECT * from table1 a, table2 b where (WHATEVER) Maybe both tables have the same column name. So I though it would be nice to access the data…
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
46
votes
10 answers

Treating an SQL ResultSet like a Scala Stream

When I query a database and receive a (forward-only, read-only) ResultSet back, the ResultSet acts like a list of database rows. I am trying to find some way to treat this ResultSet like a Scala Stream. This will allow such operations as filter,…
Ralph
  • 31,584
  • 38
  • 145
  • 282
44
votes
4 answers

Convert a Result Set from SQL Array to Array of Strings

I am querying the information_schema.columns table in my PostgreSQL database. Using a table name, the result set finds all the column names, type, and whether it is nullable (except for the primary key, 'id'). This is the query being used: SELECT…
Matt
  • 1,792
  • 5
  • 21
  • 33
42
votes
3 answers

Statement.execute(sql) vs executeUpdate(sql) and executeQuery(sql)

I have a question related to this method: st.execute(sql); where st obviously is a Statement object. Directly from this oracle java tutorial: execute: Returns true if the first object that the query returns is a ResultSet object. Use this method…
Rollerball
  • 12,618
  • 23
  • 92
  • 161
36
votes
3 answers

Difference between filtering queries in JOIN and WHERE?

In SQL I am trying to filter results based on an ID and wondering if there is any logical difference between SELECT value FROM table1 JOIN table2 ON table1.id = table2.id WHERE table1.id = 1 and SELECT value FROM table1 JOIN table2 ON…
warsong
  • 1,008
  • 2
  • 12
  • 21
36
votes
6 answers

How to find whether a ResultSet is empty or not in Java?

How can I find that the ResultSet, that I have got by querying a database, is empty or not?
Amit
  • 33,847
  • 91
  • 226
  • 299
36
votes
17 answers

Java Iterator backed by a ResultSet

I've got a class that implements Iterator with a ResultSet as a data member. Essentially the class looks like this: public class A implements Iterator{ private ResultSet entities; ... public Object next(){ entities.next(); …
Jordan Messina
  • 1,511
  • 1
  • 16
  • 25
36
votes
2 answers

When to close Connection, Statement, PreparedStatement and ResultSet in JDBC

Few questions on JDBC coding: For a single client application, do we need a Connection pool? Is it a good idea to create a Connection at the beginning and keep it alive without close it until application exit? Why? PreparedStatement is associated…
5YrsLaterDBA
  • 33,370
  • 43
  • 136
  • 210
35
votes
4 answers

Bulk insert in Java using prepared statements batch update

I am trying to fill a resultSet in Java with about 50,000 rows of 10 columns and then inserting them into another table using the batchExecute method of PreparedStatement. To make the process faster I did some research and found that while reading…
Mrinmoy
  • 1,611
  • 3
  • 18
  • 20
35
votes
3 answers

Getting the date from a ResultSet for use with java.time classes

Is there anyway to get a java.time (new in Java 8) compatible time class out of a ResultSet? I am aware you can use ResultSet's getDate or getTimestamp but these method return java.sql.Date / java.sql.Timestamp objects which are now deprecated so…
Thomas Paulin
  • 515
  • 1
  • 6
  • 12
32
votes
2 answers

Converting MySQL result array to JSON

I want to convert my database query's result array to JSON format in PHP. Here is my code: $row = mysql_fetch_array($result) I want to convert $row to JSON format and pass the JSON data to a jQuery plugin.
user213559
32
votes
7 answers

How do I get the row count in JDBC?

I've executed a JDBC query to obtain a resultset. Before iterating over it, I'd like to quickly find out how many rows were returned. How can I do this with high performance? I'm using Java 6, Oracle 11g, and the latest Oracle JDBC drivers.
Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
31
votes
5 answers

Java JDBC Lazy-Loaded ResultSet

Is there a way to get a ResultSet you obtain from running a JDBC query to be lazily-loaded? I want each row to be loaded as I request it and not beforehand.
Nathaniel Flath
  • 15,477
  • 19
  • 69
  • 94