日期:2014-05-16 浏览次数:20340 次
public static final String DBDRIVE = "oracle.jdbc.driver.OracleDriver"; public static final String DBURL = "jdbc:oracle:thin:@169.254.24.29:1521:orcl"; public static final String DBUSER = "scott"; public static final String DBPASSWORD= "tiger"; public static void main(String[] args) { Connection conn =null; PreparedStatement pstmt = null; ResultSet rs =null; String sql = "select * from user where name like ?"; try { Class.forName(DBDRIVE); conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD); pstmt = conn.prepareStatement(sql); pstmt.setString(1, "%xiaoming%"); rs = pstmt.executeQuery(); while(rs.next()) { int id = rs.getInt(1); String name = rs.getString(2); System.out.print("编号" + id + ":"); System.out.println("姓名" + name + ":"); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } }