resultset

Using a ResultSet after executing two different queries with statement.executeQuery() [duplicate]

纵饮孤独 提交于 2021-02-19 07:57:05
问题 This question already has an answer here : Invalid state, the ResultSet object is closed (1 answer) Closed 5 years ago . Given the code below: //connection stuff ResultSet rs = statement.executeQuery(query1); statement.executeQuery(query2); while(rs.next){ //code } Is the result set rs still valid even though a second statement has been executed? I know that when you close a statement the result set isn't valid any longer, but here the code is simply executing another query and not storing it

How can I identify columns when SELECTing from multiple tables with JDBC?

冷暖自知 提交于 2021-02-18 22:13:05
问题 I have two tables that I join on the id-column, they look like: +-------+ | users | +----+--+---+ | id | name | +----+------+ +-------+ | posts | +-------+------+---------+ | id | user_id | message | +----+---------+---------+ And now I want to select all posts and include the username, with: SELECT * FROM posts, users WHERE user_id = users.id And then I try to get the values with: ResultSet rs = // SQL if(rs.next()) { rs.getInt("posts.id"); ... } But I get SQLException when executing rs

How can I identify columns when SELECTing from multiple tables with JDBC?

醉酒当歌 提交于 2021-02-18 22:09:52
问题 I have two tables that I join on the id-column, they look like: +-------+ | users | +----+--+---+ | id | name | +----+------+ +-------+ | posts | +-------+------+---------+ | id | user_id | message | +----+---------+---------+ And now I want to select all posts and include the username, with: SELECT * FROM posts, users WHERE user_id = users.id And then I try to get the values with: ResultSet rs = // SQL if(rs.next()) { rs.getInt("posts.id"); ... } But I get SQLException when executing rs

JDBC - SQLITE Select to variable

吃可爱长大的小学妹 提交于 2021-02-05 11:13:45
问题 I am trying to run a query / select statement and save it in a variable. I know how to get something specific from a specific column but not from counting rows. This is working as I getting MYID specifically. ResultSet MYIDrs = stmtCFG.executeQuery( "SELECT rowid, MYID from MYINDEX order by rowid desc limit 1;" ); MYID = MYIDrs.getString("MYID"); Now I am trying to count the rows that works in SQLite client but not in the jdbc as I can't figure out what to request. this is what I have but is

Java ResultSet.getString() for Date field displaying 00:00:00.0

走远了吗. 提交于 2021-01-28 00:00:45
问题 I am using a generic method to loop through and convert a ResultSet to a String array. I am wondering why does the Date column in Oracle db value come print out as 2015-01-09 00:00:00.0 while the date in the database shows 2015-01-09 ? Here is the code, the col type in Oracle is Date while(rs.next()) { String[] arr = new String[colCount]; for(int i = 1; i <= colCount; i++) { arr[i-1] = rs.getString(i); }//end for list.add(arr); }//end while So that is part 1 of the question, part 2 of the

JDBC ResultSet internal mechanism of fetching large datasets

自闭症网瘾萝莉.ら 提交于 2021-01-07 04:24:05
问题 Does JDBC result set fetch all data in one network call for a SQL query? Consider the query select * from table where timestamp > 1597937895 . Now there are more than 1 million rows for this query. Does result set fetch all the rows in one network call? Or does it fetch batch of rows as and when the result set is read? Because I need to look at memory usage as well. Hence clarifying. I am known by the fact that ResultSet fetches all data in one network call. Is this is the only behaviour or

Java: Query ResultSet to JSON

狂风中的少年 提交于 2020-12-30 03:13:38
问题 Query to Oracle DB being sent via following code and supposed to return the query result as JSON : Connection conn ; try { Class.forName("oracle.jdbc.driver.OracleDriver"); String url = "jdbc:oracle:thin:@localhost:1521:dbname"; conn = DriverManager.getConnection(url,"username","pwd"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM table4 where ID = '5'"); while (rs.next()) { String s = rs.getString("*"); response.setContentType("application/json");