resultset

How to retrieve data using JDBC

青春壹個敷衍的年華 提交于 2019-12-12 02:12:23
问题 I have been trying with the following code. The connection is being made. But the resultSet is coming as empty (not null), whereas there are a couple of entries (2 fields each) in the database for the same. It does not enter the while condition. I'm new to JDBC, please help! My code is: import java.sql.*; public class JDBCTest123 { public static void main(String[] args) { System.out.println("oracle Connect Example."); Connection conn = null; String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";

Inserting a row into a ResultTableModel as well as Database

痞子三分冷 提交于 2019-12-12 01:51:28
问题 I have a JTable that is populated from a database. I am using a custom model ResultSetTableModel . Below is the custom model: public class ResultSetTableModel extends AbstractTableModel { private String[] columnNames; private Class[] columnClasses; private List<List<Object>> cells = new ArrayList<List<Object>>(); public ResultSetTableModel() { columnNames = new String[1]; columnNames[0] = "Result Set"; List<Object> row = new ArrayList<Object>(); row.add("No data"); cells.add(row); } public

Troubles getting results from ResultSet

安稳与你 提交于 2019-12-12 01:16:57
问题 How can I have a var which contains all the records I get from a resultset? So far I have this code: while (rs.next()) { for (int i = 1; i <= columnCount; i++) { String resultado = ""; resultado = rs.getString(i); columnValue += resultado; } jTextPane2.setText(jTextPane2.getText() + columnValue + ", "); } I want that when resultado gets the value from the rs.getString(i) , fills the var columnValue so that I have a var which SHOULD have all the records I get from the rs, but is not working.

parse String variable from database (type datetime) to LocalDateTime variable using Resultset

巧了我就是萌 提交于 2019-12-12 01:13:07
问题 I'm trying to convert a String value (initially a LocalDateTime variable) that was stored in a database (as datetime) and parse it into a LocalDateTime variable. I've tried it with a formatter: String dTP; dTP=(rs.getString("arrivedate")); DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; LocalDateTime dateTimeParked = LocalDateTime.parse(dTP,formatter); And without a formatter: String dTP; dTP=(rs.getString("arrivedate")); LocalDateTime dateTimeParked = LocalDateTime.parse

How to return result set from method in jdbc connection

雨燕双飞 提交于 2019-12-11 23:56:17
问题 This is my connetion class. i need to return resultset to specific class. but i found resultset is closed in that class. i use connectio pooling in my connection. i want to create general connection class that manages all operations for database in my application. import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql

How get the number of rows count by ResultSet in Java [duplicate]

回眸只為那壹抹淺笑 提交于 2019-12-11 23:19:53
问题 This question already has answers here : How do I get the row count in JDBC? (7 answers) Closed 5 years ago . I want to get the row count of a ResultSet . ResultSet rs; Statement s; rs=s.executeQuery("SELECT * FROM mytable"); //rs.getRowCount; ??? 回答1: You can go to the last row of the resultset and get the row number like this: resultSet.last() int count = resultSet.getRow() But this is inefficient because it has to read all the table data. Better to execute the query: SELECT COUNT(*) FROM

Best way to get result of prepared MySQL statement with maximum of one row

怎甘沉沦 提交于 2019-12-11 16:56:35
问题 I usually use this code to read/get the result of an prepared MySQL SELECT: $sqlname = $conn->prepare("SELECT name FROM test1 WHERE test2 = ?"); $sqlname->bind_param('s',$test); $sqlname->execute(); $result = $sqlname->get_result(); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $testname = $row['name']; } } But when I know that there will only be one row in the result: Do I have to use a while loop with fetch_assoc anyway or is there a better way? 回答1: When you know the

ResultSet has row count value more than Integer.MAX_VALUE. How?

喜夏-厌秋 提交于 2019-12-11 15:57:14
问题 I have the following code: //rs is a ResultSet from a preparedStatement rs.last(); this.resultCount = rs.getRow(); rs.beforeFirst(); If I execute a sql query which returns me more than Integer.MAX_VALUE rows back, what behaviour have then getRow which returns an integer value? And how can I get there the rowCount as a long value ? 来源: https://stackoverflow.com/questions/58071915/resultset-has-row-count-value-more-than-integer-max-value-how

JavaWeb(四):JDBC

妖精的绣舞 提交于 2019-12-11 13:13:54
数据持久化(persistence) 把数据保存到可掉电式存储设备中以供之后使用。 大多数情况下,特别是企业级应用,数据持久化意味着将内存中的数据保存到硬盘上加以”固化”,而持久化的实现过程大多通过各种关系数据库来完成。持久化的主要应用是将内存中的数据存储在关系型数据库中,当然也可以存储在磁盘文件、XML数据文件中。 Java中的数据存储技术 在Java中,数据库存取技术可分为如下几类: JDBC直接访问数据库 JDO技术 第三方O/R工具,如Hibernate, ibatis 等 JDBC是java访问数据库的基石,JDO、Hibernate等只是更好的封装了JDBC。 JDBC基础 JDBC(Java Database Connectivity)是一个独立于特定数据库管理系统、通用的SQL数据库存取和操作的公共接口(一组API),定义了用来访问数据库的标准Java类库,使用这个类库可以以一种标准的方法、方便地访问数据库资源。JDBC为访问不同的数据库提供了一种统一的途径,为开发者屏蔽了一些细节问题。JDBC的目标是使Java程序员使用JDBC可以连接任何提供了JDBC驱动程序的数据库系统,这样就使得程序员无需对特定的数据库系统的特点有过多的了解,从而大大简化和加快了开发过程。 没有JDBC时,直接连接,各个数据库都要单独编写连接程序 JDBC提供了一组接口,面向接口编程

How to correctly return special Spanish characters from a MS Access db with jdbc-odbc driver

倖福魔咒の 提交于 2019-12-11 12:52:43
问题 How can you return special characters from a Ms access (.accdb or .mdb) database using the jdbc-odbc driver for MS Acess databases? Converting from bytes of the result set( bytes[] bt = rs.getbytes(index_of_field) and then new String (bt, "UTF-8") or even new String (bt, "iso-8859-1") ) or getting the string ( rs.getString() ) won't work and you need a valid way to do it. 回答1: The way to get special characters like (some other special characters may also be returned successfully, however,