📄 updateemployeeexample1.java
字号:
import java.sql.*;public class UpdateEmployeeExample1{ // Private reference to an instance of the Connection Connection connection = null; // Default Constructor public UpdateEmployeeExample1( Connection conn ) { super(); connection = conn; } // Private accessor for the connection private Connection getConnection() { return connection; } // Print out the Employee Records backwards using a scrollable // ResultSet public void updateEmployees() { Statement stmt = null; ResultSet rs = null; try { // Get a scrollable ResultSet Connection conn = getConnection(); stmt = conn.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE ); // Get some fields from the employee table String sqlQuery = "SELECT EMPNO, EName, Job, MGR, HIREDATE FROM EMP"; rs = stmt.executeQuery( sqlQuery ); while( rs.next() ) { Timestamp ts = new Timestamp( System.currentTimeMillis() ); rs.updateTimestamp( "HIREDATE", ts ); // Cause the update changes to be made persistent rs.updateRow(); } rs.first(); while( rs.next() ) { String name = rs.getString( 2 ); Timestamp hireDate = rs.getTimestamp( 5 ); System.out.println( "Name: " + name + " Hire Date: " + hireDate ); } rs.close(); } catch( SQLException ex ) { ex.printStackTrace(); } } public static void main(String[] args) { // Use the previous DatabaseManager Connection conn = DatabaseManager.getConnection(); UpdateEmployeeExample1 example = new UpdateEmployeeExample1( conn ); example.updateEmployees(); // Always make sure to close the connection when you are finished try { conn.close(); } catch( SQLException ex ) { ex.printStackTrace(); } catch( Exception ex ) { ex.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -