mybaties和orcale数据库连接返回游标结果注解方式配置

import java.io.Serializable;

public class City implements Serializable{
private Integer cid;
private String cname;

public City() {
	super();
}
public Integer getCid() {
	return cid;
}
public void setCid(Integer cid) {
	this.cid = cid;
}
public String getCname() {
	return cname;
}
public void setCname(String cname) {
	this.cname = cname;
}

}

package com.my.mapper;

import java.util.Map;

import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.StatementType;

import com.my.entity.City;

public interface ICityMapper {
@Results(id = “rs”, value = {
@Result(property = “cid”, column = “CID”, id = true),
@Result(property = “cname”, column = “CNAME”)
})
@Select({“call pro_city(#{page,mode=IN,jdbcType=INTEGER},#{size,mode=IN,jdbcType=INTEGER},#{cur,mode=OUT,jdbcType=CURSOR,resultMap=rs},#{allcount,mode=OUT,jdbcType=INTEGER},#{allpage,mode=OUT,jdbcType=INTEGER})”})
@ResultType(com.my.entity.City.class)
@Options(statementType=StatementType.CALLABLE)
public void OpPage(Map map);
@Select(“select *from city c where c.cid=#{cid}”)
public City getCity(int cid);
}

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.type.JdbcType;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.my.entity.City;
import com.my.entity.User;
import com.my.service.ICityService;
import com.my.service.IUserService;

public class Test {
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
BeanFactory bf=new ClassPathXmlApplicationContext(“applicationContext.xml”);
ICityService us=(ICityService)bf.getBean(“cityService”);
Map map=new HashMap();
map.put(“page”, 1);
map.put(“size”, 5);
us.OpPage(map);
Listlist=(List)map.get(“cur”);
System.out.println(map.get(“cur”));
for (City city : list) {
System.out.println(city.getCname());
}

}

}

在Python中连接Oracle数据库可以使用cx_Oracle模块。以下是一个简单的连接示例: 1. 安装cx_Oracle模块:可以使用pip命令进行安装,如下所示: ``` pip install cx_Oracle ``` 2. 连接Oracle数据库:使用cx_Oracle.connect()方法连接到Oracle数据库,如下所示: ```python import cx_Oracle # 连接Oracle数据库 connection = cx_Oracle.connect(user="用户名", password="密码", dsn="数据库主机名:端口号/数据库实例名") ``` 3. 执行SQL语句:使用cursor对象的execute()方法执行SQL语句,如下所示: ```python # 创建cursor对象 cursor = connection.cursor() # 执行SQL语句 cursor.execute("SELECT * FROM table_name") # 获取查询结果 result = cursor.fetchall() # 关闭cursor对象和数据库连接 cursor.close() connection.close() ``` 完整示例代码如下所示: ```python import cx_Oracle # 连接Oracle数据库 connection = cx_Oracle.connect(user="用户名", password="密码", dsn="数据库主机名:端口号/数据库实例名") # 创建cursor对象 cursor = connection.cursor() # 执行SQL语句 cursor.execute("SELECT * FROM table_name") # 获取查询结果 result = cursor.fetchall() # 打印查询结果 for row in result: print(row) # 关闭cursor对象和数据库连接 cursor.close() connection.close() ``` 注意:在使用cx_Oracle模块连接Oracle数据库时,需要先安装Oracle Instant Client,并将相关路径添加到系统环境变量中。具体操作可以参考官方文档:https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@沫沫@

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值