import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

 

//预处理方式

public class preperSTest {

 

         public static void main(String[] args) throws SQLException {

                   find();

         }

 

         private static void find() throws SQLException {

                   Connection conn = null;

                   PreparedStatement ps = null;

                   ResultSet rs = null;

 

                   try {

                            // 创建连接

                            conn = JdbcUtils.getConnection();

 

                            String sql = " select id,name ,book  from  student  where id = ?";

 

                            ps = conn.prepareStatement(sql);

                            // 代替 占位符

                            ps.setInt(1, 2);

 

 

                           

                           

            rs = ps.executeQuery();

           

                             while (rs.next()) {

                             System.out.println(rs.getInt("id")+"\t"+rs.getString("name") + "\t"

                             + rs.getString("book"));

                             }

                   } finally {

                            JdbcUtils.release(rs, ps, conn);

                   }

 

         }

}

客户端:

Jdbc操作数据库  查_客户端

后台:

Jdbc操作数据库  查_java_02