获取Oracle中特定的某行某列的值

swtongxue 2017-09-11 10:20:47
比如获取Oracle中第四行第二列的这个值
...全文
720 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
swtongxue 2017-09-23
  • 打赏
  • 举报
回复
引用 8 楼 XxPingEr 的回复:
	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();
		}
	}
谢谢
XxPingEr 2017-09-21
  • 打赏
  • 举报
回复
	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();
		}
	}
swtongxue 2017-09-20
  • 打赏
  • 举报
回复
引用 4 楼 XxPingEr 的回复:
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);
		}
你好,能详细的写一下这个程序吗,这一段我看不懂
sy_05 2017-09-15
  • 打赏
  • 举报
回复
select secondCol from (select 第2列 secondCol,row_number() RN) where RN=4
冬天的糊涂神 2017-09-11
  • 打赏
  • 举报
回复
select * from (select 第2列,row_number() RN) where RN=4
XxPingEr 2017-09-11
  • 打赏
  • 举报
回复
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);
		}
XxPingEr 2017-09-11
  • 打赏
  • 举报
回复

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);
		}

参考一下吧
swtongxue 2017-09-11
  • 打赏
  • 举报
回复
那怎么才能在java里得到这个值,连接都建立好了
XxPingEr 2017-09-11
  • 打赏
  • 举报
回复
。。。先查列后查行 SELECT COUNT FROM product WHERE id = 4

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧