resultset

Implementations of RowSet, CachedRowSet etc

a 夏天 提交于 2019-12-17 18:33:19
问题 Until today I was working with ResultSet when handling results from queries. But today I read a little about RowSet and CachedRowset and I realized they can serve my purposes better. While in all the examples I read where RowSet and CachedRowSet were referred to as object, when I tried it myself in my code I realized those are interfaces and in the examples they use some implementation of those interfaces. Now my question is where do I find those implementations, and is there something

rs.last() gives Invalid operation for forward only resultset : last

我的梦境 提交于 2019-12-17 16:32:47
问题 I am trying to get the row count of a result set by: rs.last(); int row_count = rs.getRow(); but im getting an Invalid operation for forward only resultset : last error. The result set is getting its data from an Oracle 10g database. Here is how i set up my connection: Class.forName("oracle.jdbc.driver.OracleDriver"); String connectionString = "jdbc:oracle:thin:@" + oracle_ip_address + ":" + oracle_db_port + ":" + oracle_db_sid; Connection conn = DriverManager.getConnection(connectionString,

Convert a Result Set from SQL Array to Array of Strings

旧街凉风 提交于 2019-12-17 15:47:18
问题 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 column_name, is_nullable,data_type FROM information_schema.columns WHERE lower(table_name) = lower('TABLE1') AND column_name != 'id' ORDER BY ordinal_position; I have a string array for each of these results and I am trying to use the ResultSet

Java SQL: Statement.hasResultSet()?

半腔热情 提交于 2019-12-17 14:33:29
问题 My app uses MySQL on one platform and SQLite on another, as such there are differences, such as that when using query like DELETE FROM USERS : On MySQL , PreparedStatement.getResultSet() will return null . On SQLite , PreparedStatement.getResultSet() will throw java.sql.SQLException: no ResultSet available . This may or may not be a bug in SQLite implementation (I think it is supposed to return null ), but I have to deal with this somehow. I could use a try { ... } catch (SQLException e) { ..

Treating an SQL ResultSet like a Scala Stream

£可爱£侵袭症+ 提交于 2019-12-17 10:20:05
问题 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 , map , etc., while not consuming large amounts of RAM. I implemented a tail-recursive method to extract the individual items, but this requires that all items be in memory at the same time, a problem if the ResultSet is very large: // Iterate through

How do I get the row count in JDBC?

微笑、不失礼 提交于 2019-12-17 09:40:28
问题 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. 回答1: You're going to have to do this as a separate query, for example: SELECT COUNT(1) FROM table_name Some JDBC drivers might tell you but this is optional behaviour and, more to the point, the driver may not know yet. This can be due to how the query is

Get MySQL Query Results as Their Native Data Type?

吃可爱长大的小学妹 提交于 2019-12-17 07:33:27
问题 I have tried fetching MySQL query results using mysql_fetch_row() and mysql_result() and numeric values are being returned as strings. Is there any way to fetch the data as its datatype stored in the table? The application will be querying many different queries so I will be unable to cast the values as the intended datatype on a 1 by 1 basis. 回答1: I don't think getting data in their native datatypes (i.e. anything else that strings) can be done in PHP 5.2... In PHP 5.3, it becomes possible,

JDBC技术总结(一)

蓝咒 提交于 2019-12-17 04:02:34
1. JDBC简介 SUN公司为了简化、统一对 数据库 的操作,定义了一套 Java 操作数据库的规范,称之为JDBC,JDBC不能直接操作数据库,JDBC通过接口加载数据库的驱动,然后操作数据库。JDBC:Java Data Base Connectivity,它主要由接口组成。组成JDBC的2个包为java.sql和javax.sql。开发JDBC应用需要这2个包的支持外,还需要导入相应JDBC的数据库实现(即数据库驱动)。 2. JDBC快速入门 编程从user表中读取数据,并打印在控制台窗口中。 2.1 搭建实验环境 create database test Character set utf8 collate utf8_general_ci; use test create table user ( id int primary Key, name varchar(20), password varchar(20), email varchar(20), birthday Date ); insert into user(id,name,password,email,birthday) values(1,'zw','123','zw@sina.com','1990-09-19'); insert into user(id,name,password,email

java day53【 Mybatis框架概述 、 Mybatis 框架快速入门、自定义 Mybatis 框架 】

人走茶凉 提交于 2019-12-16 21:56:14
第1章 框架概述 1.1 什么是框架 1.1.1 什么是框架   框架(Framework)是整个或部分系统的可重用设计,表现为一组抽象构件及构件实例间交互的方法;另一种 定义认为,框架是可被应用开发者定制的应用骨架。前者是从应用方面而后者是从目的方面给出的定义。 简而言之,框架其实就是某种应用的半成品,就是一组组件,供你选用完成你自己的系统。简单说就是使用别 人搭好的舞台,你来做表演。而且,框架一般是成熟的,不断升级的软件。 1.1.2 框架要解决的问题   框架要解决的最重要的一个问题是技术整合的问题,在 J2EE 的 框架中,有着各种各样的技术,不同的 软件企业需要从 J2EE 中选择不同的技术,这就使得软件企业最终的应用依赖于这些技术,技术自身的复杂性和技 术的风险性将会直接对应用造成冲击。而应用是软件企业的核心,是竞争力的关键所在,因此应该将应用自身的设 计和具体的实现技术解耦。这样,软件企业的研发将集中在应用的设计上,而不是具体的技术实现,技术实现是应 用的底层支撑,它不应该直接对应用产生影响。   框架一般处在低层应用平台(如 J2EE)和高层业务逻辑之间的中间层。 1.1.3 软件开发的分层重要性   框架的重要性在于它实现了部分功能,并且能够很好的将低层应用平台和高层业务逻辑进行了缓和。为了实现 软件工程中的“高内聚、低耦合”。把问题划分开来各个解决,易于控制

反射——CRUD小工具

浪子不回头ぞ 提交于 2019-12-16 10:45:02
反射——CRUD小工具 用反射封装了一个用于增删改查的工具类。现在市面上已经有很多成熟的持久层框架,所以这里只是为了熟悉反射机制,且了解一点市面上持久层框架最基础的原理。写的这个工具类有一些限制,比如实体类必须与表名一致,主键名字必须是id,实体类名字与数据库表名必须一致(如UserEntity – userEntity),实体类所有的字段和表的字段需要一致,究其原因是因为没有自己的专门用于关系映射的配置文件或者注解,想要解决关系映射也简单,将映射关系写进一个配置文件或者自己做注解开发做映射。 1、工具类 package com . xsl . util ; import java . lang . reflect . Constructor ; import java . lang . reflect . Field ; import java . sql . * ; import java . util . ArrayList ; import java . util . List ; /** * 一个Crud的小工具类,可以单表增删改查任何实体类 * 前提:表名与类名一致,表名开头小写,类名开头大写,类字段与表字段一致,表字段没有多余的无用字段 * @param <T>实体类 * @param <K>主键 * @author xsl */ public class