resultset

When accessing ResultSets in JDBC, is there an elegant way to distinguish between nulls and actual zero values?

泪湿孤枕 提交于 2020-01-03 12:02:19
问题 When using JDBC and accessing primitive types via a result set, is there a more elegant way to deal with the null/0 than the following: int myInt = rs.getInt(columnNumber) if(rs.wasNull())? { // Treat as null } else { // Treat as 0 } I personally cringe whenever I see this sort of code. I fail to see why ResultSet was not defined to return the boxed integer types (except, perhaps, performance) or at least provide both. Bonus points if anyone can convince me that the current API design is

When accessing ResultSets in JDBC, is there an elegant way to distinguish between nulls and actual zero values?

懵懂的女人 提交于 2020-01-03 12:01:53
问题 When using JDBC and accessing primitive types via a result set, is there a more elegant way to deal with the null/0 than the following: int myInt = rs.getInt(columnNumber) if(rs.wasNull())? { // Treat as null } else { // Treat as 0 } I personally cringe whenever I see this sort of code. I fail to see why ResultSet was not defined to return the boxed integer types (except, perhaps, performance) or at least provide both. Bonus points if anyone can convince me that the current API design is

Avoid returning result set from stored procedure

☆樱花仙子☆ 提交于 2020-01-03 07:06:26
问题 Assume I have some stored procedure (and I can't change it) which is returning a result set: create procedure test_procedure as begin select 1 end I know that I can insert result set into table, so it would be hidden to the calling code: declare @t table(i int) insert into @t exec test_procedure Are there any other ways to hide returning result set from the calling code? Updated It looks like I've been a bit confusing. I'm looking only for T-SQL answers (not .NET ones). 回答1: No, there is no

JDBC executeQuery() returning both ResultSet and output params

家住魔仙堡 提交于 2020-01-03 03:15:59
问题 I am calling one sp with few out params and as per my requirement,I need to use ResultSet on some condition and out params on other conditions. But using executeQuery(), I am getting, JZ0R0: ResultSet has already been closed error.(I am using Sybase 15) Here is the example: Connection conn = ~~; CallableStatement cstmt = conn.prepareCall("{call my_sp(?)"); cstmt.registerOutParameter(1,java.sql.Types.INTEGER); ResultSet rs = cstmt.executeQuery(); If i try to do, below code now, int res = cstmt

How to paginate multiple results in CakePHP?

醉酒当歌 提交于 2020-01-02 00:11:08
问题 How can I use the paginatation helper in cakePHP to show more than one result set on the same page? They would page independently. EDIT: I found out one reason why it can't do that is because the pagination helper would get its URL from the controller/action and then appends its parameters at the end. If it pulled the url from the address bar, had its own unique variable and then did an str_replace to get the next one to navigate to if you've already paged, or append it if it doesn't exist.

Editing JTable from RestulSet Table

大兔子大兔子 提交于 2020-01-01 19:48:08
问题 Continuing this question. My problem is that I can not edit my JTable. I get an exception and the Object value instead of what I should be seeing. I am using the ResultSet Table code with a MS-Access database and with a few modifications. My code can be found here. I run into an error when I rs.updateRow() is called. java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Error in row. I did a google search on this error with updateRow() and not much came up. The only real answer I

JDBC is not executing SHOW DATABASES command [closed]

ε祈祈猫儿з 提交于 2020-01-01 18:56:50
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 months ago . i want to get a list of databases stored in mysql and put in java table using command "show databases" via a resultset. but its not working. DefaultTableModel model=(DefaultTableModel)dbTbl.getModel(); try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql//localhost

Behaviour of ResultSet.TYPE_SCROLL_SENSITIVE

末鹿安然 提交于 2020-01-01 09:31:05
问题 I am confused about the behaviour of a ResultSet that is of type TYPE_SCROLL_SENSITIVE . My understanding of this is: I execute a select query that returns me a result set. I print out the value of a particular column in the first row. I then execute Thread.sleep(10000) , which halts the program for 10 seconds. While the program is sleeping, I manually do an update to the same column in the DB (through the SQL prompt). After 10 seconds, I again print the value of the same column in the first

Using a query inside RowMapper

空扰寡人 提交于 2019-12-31 04:50:40
问题 In java i would do something like below to iterate the resultset and form the query, public Map<String, List<MODEL>> fun(){ Map<String, List<MODEL>> map = new TreeMap<String, List<MODEL>>(); LinkedHashSet<String> set = new LinkedHashSet<String>(); String sql = "select distinct(column) from table where conditions orderby column "; ResultSet rslt = stmt.executeQuery(sql); while (rslt.next()) { al.add(rslt.getString(1)); } for (String s : al) { List<MODEL> list = new ArrayList<MODEL>(); String

How to load MySQLi result set into two-dimensional array?

拜拜、爱过 提交于 2019-12-30 09:36:15
问题 I've got a problem with the mysqli result set. I have a table that contains a bunch of messages. Every table row represents one message. I have a few columns like ID, title, body, and 'public'. The public column contains booleans, that specify if the message is to be displayed to everyone, or just to the person who posted it. I have a page where I want to display all public messages, and if you click on a message, you get a page with the single message, and some extra options. To do this, I