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(); } } }
相关推荐
This shows how to retrieve the text from the current selection in a listbox.
This demonstrates how to write and retrieve information from the registry.
This demonstrates how to retrieve the file size from a specified file.
Demonstrates how to retrieve various information about specific windows
This demonstrates how to retrieve information about Battery Powered machines.
This module demostrates how to retrieve information about a joystick. This is a great module for game programmers.
This is an example of how to retrieve the system colors and display them on your form.
information retrieve textbook from Standford university
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.
You'll also learn how to save and retrieve your data using SQLite, iPhone's built-in database management system. You'll learn how to draw using Quartz 2D and OpenGL ES. You'll add MultiTouch ...
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(), ...
Query Retrieve SCP Emulator
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 ...
描述PB的并发控制机制,详细解释Row changed between retrieve and update错误出现的原因,以及处理方法。对学习PB有一定的帮助。
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! Beginning iPhone Development with Swift 3 ...
How do you display players' scores and achievements? How do you create Game Center accounts and add friends? Each recipe in this book includes a simple code solution you can put to work immediately, ...
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 ...