Only for reference.
This example shows how to read data from a ResultSet returned by a executing an SQL query to a table in database.
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class ResultSetExample { public static void main(String[] args) throws Exception { Connection connection = getConnection(); try { String query = "select id, title, publisher, year, price from books"; PreparedStatement ps = connection.prepareStatement(query); ResultSet rs = ps.executeQuery(); while (rs.next()) { // Read values using column name String id = rs.getString("id"); String title = rs.getString("title"); String publisher = rs.getString("publisher"); // Read values using column index int year = rs.getInt(4); float price = rs.getFloat(5); System.out.printf("%s. %s, %s, %d, %f\n", id, title, publisher, year, price); } } finally { closeConnection(connection); } } private static Connection getConnection() throws Exception { Connection connection = null; Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://localhost/bookstore", "root", ""); return connection; } private static void closeConnection(Connection connection) throws SQLException { if (connection != null && !connection.isClosed()) { connection.close(); } } }
相关推荐
标题中的“write and retrieve information from”指的是在计算机的注册表中进行读写操作。注册表是Windows操作系统中存储系统和应用程序设置的关键数据库。通过修改注册表,用户或开发者可以精细控制系统的配置,...
在IT行业中,尤其是在软件开发领域,常常需要与各种控件打交道,以实现用户界面的交互。本示例主要关注的是如何从列表框(ListBox)中获取当前选中的文本,这是一个常见的任务,尤其在Windows应用程序中。...
描述中提到,“This demonstrates how to retrieve the file size from a specified file”,这提示我们关注的是一个实际的代码示例或者教程,它将展示如何从给定的文件路径中获取文件的大小信息。这通常涉及到读取...
This module demostrates how to retrieve information about a joystick. This is a great module for game programmers.
I have an SDF file and I would like to retrieve its schema and query it ... How can I do this? I have no Visual Studio installed on the machine and I would like to install as little software as possible.
标题中的“Demonstrates how to retrieve various information about speci”似乎是一个不完整的句子,推测完整的意思可能是“演示如何获取特定窗口的各种信息”。这个主题通常涉及Windows API编程,特别是与图形...
I need to retrieve misc. UNIX user information such as one's home directory coming from MySQL. Can pam-mysql do this? How can I quickly tell in which way a given password is encrypted, PASSWORD(), ...
在IT领域,电池信息的获取是一项基础但重要的任务,尤其对于移动设备和便携式电子设备而言。这个压缩包提供了一种方法来实现这一功能,它包含了一个名为"BATMETER"的项目,用于显示和管理电池状态。...
You'll also learn how to save and retrieve your data using SQLite, iPhone's built-in database management system. In addition, you'll also learn about Core Data, an important persistence mechanism ...
How do you use Windows PowerShell to navigate the filesystem, manage files and folders, or retrieve a web page? This introduction to the PowerShell language and scripting environment provides more ...
You'll also learn how to save and retrieve your data using SQLite, iPhone's built-in database management system. In addition, you'll also learn about Core Data, an important persistence ...
You'll also learn how to save and retrieve your data using SQLite, iPhone's built-in database management system. In addition, you'll also learn about Core Data, an important persistence ...
Query Retrieve SCP Emulator
PB并发控制与Row changed between retrieve and update详解 PB并发控制机制是指在多用户同时访问数据库时,防止数据不一致和丢失的机制。PowerBuilder 提供了多种并发控制策略,包括Key Columns、Key and ...
在编程领域,尤其是在Windows应用程序开发中,经常需要与系统颜色打交道。系统颜色指的是操作系统为界面元素(如按钮、文本框等控件)预定义的一系列色彩。这些颜色可以根据用户的操作系统主题进行调整,确保应用...
根据描述,“information retrieve textbook from Standford university”进一步明确了这是一本来自斯坦福大学的信息检索教材。 #### 二、核心知识点概述 本书主要涵盖了信息检索领域的基础知识和高级技术,内容...
anyString += childS[i].tagName == "BR" ? '\n' : childS[i].innerText; else if (childS[i].nodeType == 3) anyString += childS[i].nodeValue; } return anyString; }); HTMLElement.prototype.__...
You’ll also learn how to save and retrieve your data using a variety of persistence techniques, including Core Data and SQLite. And there’s much more! What You Will Learn: Everything you need ...
You’ll also learn how to save and retrieve your data using a variety of persistence techniques, including Core Data and SQLite. And there’s much more! What You Will Learn: Everything you need to ...