81,094
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
try {
//获取oracle的连接Driver
Class.forName("oracle.jdbc.driver.OracleDriver");
//获取oracle驱动
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe", "CRM", "crm");
//执行需要查询的条件
PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM T_CUSTOMER");
//获取查询结果集
ResultSet resultSet = prepareStatement.executeQuery();
//遍历结果集
while(resultSet.next()){
System.out.println(resultSet.getString("C_ADDRESS"));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Connection connection = null;
PreparedStatement statement = null;
try {
connection = BaseDao.getConnection();
//select count from product where id = ?
//statement.setLong(1, 4);
statement = connection.prepareStatement("select count from product where id = ?");
// 编号
statement.setLong(1,4);
// 执行语句
statement.execute();
} catch (SQLException e) {
e.printStackTrace();
} finally {
BaseDao.closeAll(null, statement, connection);
}
Connection connection = null;
CallableStatement statement = null;
Long id = 0L;
try {
connection = BaseDao.getConnection();
statement = connection.prepareCall("{call pro_owners_add(?,?,?,?,?,?)}");
statement.setString(1, owners.getName());
statement.setLong(2, owners.getAddress());
statement.setString(3, owners.getHousenumber());
statement.setString(4, owners.getWatermeter());
statement.setLong(5, owners.getOwnertypeid());
statement.registerOutParameter(6, OracleTypes.NUMBER);
statement.execute();
id = statement.getLong(6);
} catch (Exception e) {
e.printStackTrace();
} finally {
BaseDao.closeAll(null, statement, connection);
}
参考一下吧