?? preparedstatementtest.java
字號(hào):
/* * PreparedStatementTest.java * * Created on June 9, 2005, 4:28 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package ch01;import java.sql.*;import javax.sql.*;import common.*;/** * * @author kevin */public class PreparedStatementTest { /** Creates a new instance of PreparedStatementTest */ public PreparedStatementTest() { } public static void main(String[] args){ Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; try{ ConnectionFactory factory = ConnectionFactory.getConnectionFactory(); conn = factory.getConnection(); pstmt = conn.prepareStatement("insert into simple_tbl (id, name) values (?,?)"); pstmt.setInt(1, 900); pstmt.setString(2, "kevin"); int number = pstmt.executeUpdate(); System.out.println("crate record: " + number); pstmt.setInt(1, 90); pstmt.setString(2, "ding"); number = pstmt.executeUpdate(); pstmt = conn.prepareStatement("select id, name from simple_tbl where id = ?"); pstmt.setInt(1, 900); rs = pstmt.executeQuery(); while(rs.next()){ System.out.println(rs.getInt("id")); System.out.println(rs.getString("name")); } }catch(Exception e){ e.printStackTrace(); }finally{ DBUtils.close(rs, pstmt, conn); } }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -