⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preparedstatementtest.java

📁 这是一本描述JDBC数据库的书籍
💻 JAVA
字号:
/* * 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);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -