resultset

Looping on values, creating dynamic query and adding to result set

落爺英雄遲暮 提交于 2019-12-24 02:43:21
问题 I have the following problem. I am an experienced Java programmer but am a bit of a n00b at SQL and PL/SQL. I need to do the following. 1 Pass in a few arrays and some other variables into a procedure 2 Loop on the values in the arrays (they all have the same number of items) and dynamically create an SQL statement 3 Run this statement and add it to the result set (which is an OUT parameter of the procedure) I already have experience of creating an SQL query on the fly, running it and adding

Django-sphinx result filtering using attributes?

淺唱寂寞╮ 提交于 2019-12-23 17:12:10
问题 I was going through the django-sphinx documentation, and it looks like it allows you to filter search results using attributes , queryset = MyModel.search.query('query') results1 = queryset.order_by('@weight', '@id', 'my_attribute') results2 = queryset.filter(my_attribute=5) results3 = queryset.filter(my_other_attribute=[5, 3,4]) results4 = queryset.exclude(my_attribute=5)[0:10] From some examples, these attributes seem to be something you specify in the sphinx configuration file, rather than

Manually add data to a Java ResultSet

佐手、 提交于 2019-12-23 16:52:56
问题 I'm not sure if this might be a rather stupid question. But is it possible to manually add data/values into a java resultset? For instance if I already have an existing populated ResultSet, is there a way to add more data ontop of it? //if this was possible for instance ResultSet rs; rs.setData("someValue"); Thanks! 回答1: You can wrap any JDBC ResultSet with your custom implementation: public class MyResultSet implements ResultSet { // Delegate most implementations to the underlying database

isLast() method for a TYPE_FORWARD_ONLY result set

江枫思渺然 提交于 2019-12-23 11:56:15
问题 I have been trying to search for a way in which I would know if I am on the last row of my result set and I found the isLast() method. I did something like: if(rs.isLast()) { //do some operation here } But it game me an error: The requested operation is not supported on forward only result sets. I searched for a solution and it said that I should change the TYPE_FORDWARD_ONLY. But right now, I was wondering if there is a way for me to know if I am in the last record set by using the TYPE

The statement did not return a result set. Java Error

岁酱吖の 提交于 2019-12-23 08:58:27
问题 I am trying to delete data from a table from java using JDBC. First I am counting the no of rows and making sure the table is not empty and then Truncating the data. Here is the code I am using Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://m-i:1433;databaseName=Tes", "sa", "Password"); Statement cnnt= con.createStatement(); Statement del1 = con.createStatement(); ResultSet rs = cnnt.executeQuery("Select count(lea)

CachedRowSet: can it still be used to hold ResultSet data?

痴心易碎 提交于 2019-12-23 08:28:18
问题 I would like to write a java function that takes in a SQL query and returns a ResultSet for processing elsewhere. This can't be done as a ResultSet is dead once the connection is closed. Googling around I found a VERY OLD (2004) OReilly article that had something that looked like the cure: CachedRowSet. You just drop in your ResultSet, the CachedRowSet saves the data, lets you close the connection and play with the data elsewhere using the returned CachedRowSet. The article references

How to retrieve values from Result set and use it for calculations

╄→гoц情女王★ 提交于 2019-12-23 05:41:05
问题 I am using cucumber with Java and I want to calculate the tax. To do so I am connecting to data base and fetching the Gross Amount from data base. Below are the Gross pension values which result set has returned 248.36, 125.36,452.36,578.35,456.77, But now tax is getting calculated only for last value i.e, 456.77.I want to calculate tax for all the values. How do I do it? Below is the code which I have tried while(rs.next()) { //To retrieve the first column GrossPension = rs.getFloat(

How to retrieve values from Result set and use it for calculations

牧云@^-^@ 提交于 2019-12-23 05:41:01
问题 I am using cucumber with Java and I want to calculate the tax. To do so I am connecting to data base and fetching the Gross Amount from data base. Below are the Gross pension values which result set has returned 248.36, 125.36,452.36,578.35,456.77, But now tax is getting calculated only for last value i.e, 456.77.I want to calculate tax for all the values. How do I do it? Below is the code which I have tried while(rs.next()) { //To retrieve the first column GrossPension = rs.getFloat(

Display tables of a database in java

点点圈 提交于 2019-12-23 04:25:03
问题 I'm working on a java application, and I want to display the list of the tables in a Mysql database, I searched on the net and I found that "SHOW TABLES FROM [DB]" is the appropriate request, but how can I dispaly the result of this last on a java swing/awt application, PS : I tried to put the result of the request on a resultset, res = sta.executeQuery("SHOW TABLES FROM sinpec "); but it doesnt work ... How can I proceed ? 回答1: Please try this query:- SELECT TABLE_NAME FROM INFORMATION

how can i close the resultSet, prepareStatement, conn in several methods below to avoid rs close and connection pool getting jammed

[亡魂溺海] 提交于 2019-12-23 02:05:30
问题 the whole data operation is below. i want to close close each and every resource without interfering with the next connection. should i change the constructor to a connection() mthod then have a disconnect() mthod, but after doing so where should i public class DataBean{ private Connection conn = null; private ResultSet res = null; private InitialContext context; private DataSource datasource; private Statement stmt=null; private java.sql.PreparedStatement prepar = null; private java.sql