无人机飞控师初学者买那种飞控比较好

Spring中使用JDBC做的增删改查
有三种方式使用JDBC。1、使用JdbcTemplate类,实现使用JDBC ,参数是用object数组传递的 业务类:public class UserDaoImpl implements UserDao{
// 定义一个Jdbc
private JdbcT
// 必须有set 方法,因为是通过set方法装配的
public void setJt(JdbcTemplate jt) {
public void delete(int id) {
// TODO Auto-generated method stub
String sql="delete from user where id="+
int temp=this.jt.update(sql);
if(temp&0){
System.out.println("删除成功!");
System.out.println("删除失败!");
public void insert(User entity) {
// TODO Auto-generated method stub
String sql="insert into user(name,age,sex) values(?,?,?)";
Object obj[]={entity.getName(),entity.getAge(),entity.getSex()};
int temp=this.jt.update(sql,obj);
if(temp&0){
System.out.println("插入成功!");
System.out.println("插入失败!");
public List&User& selectAll() {
String sql="select * from user";
List list=this.jt.query(sql,new RowMapper(){
public Object mapRow(ResultSet rs, int row) throws SQLException {
// TODO Auto-generated method stub
User user=new User();
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setAge(rs.getInt("age"));
user.setSex(rs.getString("sex"));
System.out.println(list.size());
// TODO Auto-generated method stub
public User selectById(int id) {
// TODO Auto-generated method stub
String sql="select id,name,age,sex from user where id="+
User user=(User)jt.queryForObject(sql, new RowMapper(){
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
// TODO Auto-generated method stub
User user=new User();
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setAge(rs.getInt("age"));
user.setSex(rs.getString("sex"));
public void update(User entity) {
// TODO Auto-generated method stub
String sql="update user set name=?,age=?,sex=? where id=?";
Object obj[]={entity.getName(),entity.getAge(),entity.getSex(),entity.getId()};
int temp=jt.update(sql,obj);
if(temp&0){
System.out.println("更新成功!");
System.out.println("更新失败!");
Xml中的部分代码:&!-- 分散配置 --&
&context:property-placeholder location="jdbc.properties" /&
c3p0的数据源,设置它是为了配置jbdcTemplate--&
&bean id="comboPooledDataSource" class="com.mchange.boPooledDataSource"&
&!-- 驱动程序 --&
&property name="driverClass"&
&value&${driverClass}&/value&
&/property&
&!-- 用户名 --&
&property name="user"&
&value&${username}&/value&
&/property&
&!-- 密码 --&
&property name="password"&
&value&${password}&/value&
&/property&
&!-- url --&
&property name="jdbcUrl"&
&value&${url}&/value&
&/property&
&!-- 最大池数 --&
&property name="maxPoolSize"&
&value&${c3p0.pool.max}&/value&
&/property&
&!-- 最小池数 --&
&property name="minPoolSize"&
&value&${c3p0.pool.min}&/value&
&/property&
&!-- 初始化的池数 --&
&property name="initialPoolSize"&
&value&${c3p0.pool.init}&/value&
&/property&
&!-- 配置jdbcTemplate的bean ,设置它是为了设置业务bean中的jdbcTemplate参数--&
&bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&
&constructor-arg ref="comboPooledDataSource" /&
&!-- 设置业务bean --&
&bean id="userDaoImpl" class="cn.csdn.dao.UserDaoImpl"&
&property name="jt" ref="jdbcTemplate" /&
2、使用NamedParameterJdbcTemplate类,实现JDBC,参数是用Map集合传递的业务类:public class UserDaoImpl2 implements UserDao{
// 定义一个Jdbc
private NamedParameterJdbcT
// 必须有set 方法,因为NamedParameterJdbcTemplate类是用set方法加载的
public void setNpjt(NamedParameterJdbcTemplate npjt){
this.npjt=
public void delete(int id) {
// TODO Auto-generated method stub
String sql="delete from user where id=:id";
Map&String,Object& map=new HashMap&String,Object&();
map.put("id", id);
int temp=this.npjt.update(sql,map);
if(temp&0){
System.out.println("删除成功!");
System.out.println("删除失败!");
public void insert(User entity) {
// TODO Auto-generated method stub
String sql="insert into user(name,age,sex) values(:name,:age,:sex)";
Map&String,Object& map=new HashMap&String,Object&();
map.put("name", entity.getName());
map.put("age", entity.getAge());
map.put("sex", entity.getSex());
int temp=npjt.update(sql, map);
if(temp&0){
System.out.println("插入成功!");
System.out.println("插入失败!");
public List&User& selectAll() {
String sql="select * from user";
List list=this.npjt.queryForList(sql, new HashMap());
List list=npjt.query(sql, new HashMap(),new RowMapper(){
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
// TODO Auto-generated method stub
User user=new User();
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setAge(rs.getInt("age"));
user.setSex(rs.getString("sex"));
System.out.println(list.size());
public User selectById(int id) {
// TODO Auto-generated method stub
String sql="select id,name,age,sex from user where id=1";
Map&String,Object& map=new HashMap&String,Object&();
map.put("id", id);
User user=(User)npjt.queryForObject(sql, map, new RowMapper(){
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
User user=new User();
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setAge(rs.getInt("age"));
user.setSex(rs.getString("sex"));
public void update(User entity) {
// TODO Auto-generated method stub
String sql="update user set name=:name,age=:age,sex=:sex where id=:id";
Map&String,Object& map=new HashMap&String,Object&();
map.put("name", entity.getName());
map.put("age", entity.getAge());
map.put("sex", entity.getSex());
map.put("id", entity.getId());
int temp=npjt.update(sql, map);
if(temp&0){
System.out.println("更新成功!");
System.out.println("更新失败!");
xml中的代码:&!-- 分散配置 --&
&context:property-placeholder location="jdbc.properties" /&
c3p0的数据源,设置它是为了配置jbdcTemplate--&
&bean id="comboPooledDataSource" class="com.mchange.boPooledDataSource"&
&!-- 驱动程序 --&
&property name="driverClass"&
&value&${driverClass}&/value&
&/property&
&!-- 用户名 --&
&property name="user"&
&value&${username}&/value&
&/property&
&!-- 密码 --&
&property name="password"&
&value&${password}&/value&
&/property&
&!-- url --&
&property name="jdbcUrl"&
&value&${url}&/value&
&/property&
&!-- 最大池数 --&
&property name="maxPoolSize"&
&value&${c3p0.pool.max}&/value&
&/property&
&!-- 最小池数 --&
&property name="minPoolSize"&
&value&${c3p0.pool.min}&/value&
&/property&
&!-- 初始化的池数 --&
&property name="initialPoolSize"&
&value&${c3p0.pool.init}&/value&
&/property&
&!-- 配置jdbcTemplate的bean ,设置它是为了设置业务bean中的jdbcTemplate参数--&
&bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate"&
&constructor-arg ref="comboPooledDataSource"/&
&!-- 设置业务bean --&
&bean id="userDaoImpl" class="cn.csdn.dao.UserDaoImpl2"&
&property name="npjt" ref="namedParameterJdbcTemplate" /&
3、使用SimpleJdbcTemplate类,实现JDBC,参数是用可变参数传递的业务类:public class UserDaoImpl3 implements UserDao{
// 定义一个Jdbc
private SimpleJdbcT
// 必须有set 方法
public void setSjt(SimpleJdbcTemplate sjt){
public void delete(int id) {
// TODO Auto-generated method stub
String sql="delete from user where id=?";
int temp=this.sjt.update(sql, id);
if(temp&0){
System.out.println("删除成功!");
System.out.println("删除失败!");
public void insert(User entity) {
// TODO Auto-generated method stub
String sql="insert into user(name,age,sex) values(?,?,?)";
int temp=sjt.update(sql,entity.getName(),entity.getAge(),entity.getSex());
if(temp&0){
System.out.println("插入成功!");
System.out.println("插入失败!");
public List&User& selectAll() {
String sql="select * from user";
List list=this.sjt.queryForList(sql);
System.out.println(list.size());
public User selectById(int id) {
// TODO Auto-generated method stub
String sql="select id,name,age,sex from user where id=?";
User user=(User) sjt.queryForObject(sql, new ParameterizedRowMapper() {
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
User user=new User();
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setAge(rs.getInt("age"));
user.setSex(rs.getString("sex"));
public void update(User entity) {
// TODO Auto-generated method stub
/**第一种方法*/
String sql="update user set name=?,age=?,sex=? where id=?";
int temp=sjt.update(sql, entity.getName(),entity.getAge(),entity.getSex(),entity.getId());
/**第二种方法*/
String sql="update user set name=:name,age=:age,sex=:sex where id=:id";
Map&String,Object& map=new HashMap&String,Object&();
map.put("name", entity.getName());
map.put("age", entity.getAge());
map.put("sex", entity.getSex());
map.put("id", entity.getId());
int temp=sjt.update(sql, map);
if(temp&0){
System.out.println("更新成功!");
System.out.println("更新失败!");
xml中的部分代码:&!-- 分散配置 --&
&context:property-placeholder location="jdbc.properties" /&
c3p0的数据源,设置它是为了配置jbdcTemplate--&
&bean id="comboPooledDataSource" class="com.mchange.boPooledDataSource"&
&!-- 驱动程序 --&
&property name="driverClass"&
&value&${driverClass}&/value&
&/property&
&!-- 用户名 --&
&property name="user"&
&value&${username}&/value&
&/property&
&!-- 密码 --&
&property name="password"&
&value&${password}&/value&
&/property&
&!-- url --&
&property name="jdbcUrl"&
&value&${url}&/value&
&/property&
&!-- 最大池数 --&
&property name="maxPoolSize"&
&value&${c3p0.pool.max}&/value&
&/property&
&!-- 最小池数 --&
&property name="minPoolSize"&
&value&${c3p0.pool.min}&/value&
&/property&
&!-- 初始化的池数 --&
&property name="initialPoolSize"&
&value&${c3p0.pool.init}&/value&
&/property&
&!-- 配置jdbcTemplate的bean ,设置它是为了设置业务bean中的jdbcTemplate参数--&
&bean id="simpleJdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate"&
&constructor-arg ref="comboPooledDataSource"/&
&!-- 设置业务bean --&
&bean id="userDaoImpl" class="cn.csdn.dao.UserDaoImpl3"&
&property name="sjt" ref="simpleJdbcTemplate" /&jdbc对数据库的操作对于java web来说是非常重要的,当然现在有很多操作数据库的框架供我们操作,但是究其根本,都是封装了jdbc的:所以我把它总结总结我的使用方法:
主要的几个对象:&&& PreparedStatement ps = conn.prepareStatement(sql);&&&&&&&&&&&& 查询使用:ResultSet rs = ps.executeQuery();&&& 增删改使用:ps.executeUpdate()
我一般使用一个静态类(也可不静态),来封装数据库的直接操作:
public class sqlDao {
&private static final String Driver = &com.mysql.jdbc.Driver&;&&&&&&&&&&&&&&&&&&& //驱动
&private static final String Url = &jdbc:mysql://localhost:3309/sshtext?useUnicode=true&characterEncoding=gbk&;&&&&&//为了应对乱码加了后面的编码
&pvate static final String Username = &root&;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //账号
&private static final String Password = &123456&;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //密码
private Connection conn =
public void connect() {&&&&&&&&&&&&&&&&&&&&&&&&&&& //连接
&&Class.forName(Driver);
&&conn = (Connection) DriverManager.getConnection(Url, Username, Password);
&&if (conn.isClosed()) {
&&&System.out.println(&connect& not success&);
&} catch (ClassNotFoundException e) {
&&// TODO Auto-generated catch block
&&e.printStackTrace();
&} catch (SQLException e) {
&&// TODO Auto-generated catch block
&&e.printStackTrace();
public void closeConn() {&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //关闭
&&if (conn != null && !conn.isClosed()) {
&&&conn.close();
&} catch (SQLException e) {
&&// TODO Auto-generated catch block
&&e.printStackTrace();
///////////////////////////////////////华丽分界线/////////////////////////////////////////
增删查找:
//类似登录,检测,查重,列出数据等等业务操作
&public String Login(AccountMessage account) {&&&&&&&&&&&&&& //传入一个实体类
&&boolean flag =
&&// TODO MODIFY
&&String temp = &&;
&&connect();
&&&String sql = &SELECT * FROM tb_user WHERE user_id = ? AND password = ?;&;&&&&&&&&&&&&&&&&&& //定义sql语句,使用占位符
&&&PreparedStatement ps = conn.prepareStatement(sql);
&&&ps.setString(1, account.getUsername());&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //设置占位符的数据
&&&ps.setString(2, account.getPassword());
&&&ResultSet rs = ps.executeQuery();&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //执行查询
&&&if (rs != null && rs.next()) {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //若查询非空,且有数据
&&&&flag =
&&&&temp = rs.getString(2);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //通过rs.getString(index)的方式获取查询行列的数据
&&&&temp = temp + &:&;
&&&&temp = temp + rs.getString(4);
&&&&temp = temp + &:&;
&&&&temp = temp + rs.getString(5);
&&} catch (SQLException e) {
&&&e.printStackTrace();
&&} finally {
&&&closeConn();
///增加:主要是注册啊,写进记录等
public boolean tieNeiRong(TieziMessage tiezi) {
&&boolean flag =
&&connect();
&&String sql = &INSERT INTO tb_tie(tie_id,username,leibie, content, lujin, time) VALUES(?,?,?,?,?,?);&;
&&&PreparedStatement ps = conn.prepareStatement(sql);
&&&ps.setString(1, tiezi.gettie_Id());
&&&ps.setString(2, tiezi.getUsername());
&&&ps.setString(3, tiezi.getleibie());
&&&ps.setString(4, tiezi.gettie_content());
&&&ps.setString(5, tiezi.getlujin());
&&&ps.setString(6, tiezi.gettime());
&&&if (ps.executeUpdate() == 1) {
&&&&flag =
&&} catch (SQLException e) {
&&&// TODO Auto-generated catch block
&&&e.printStackTrace();
public boolean Delete_tiezi(int tie_id) {
&&connect();
&&boolean flag =
&&&&String sql =&delete& from tb_tie where tie_id =&+tie_id+&;&;&&&&&&&&&&&&&&&&&&&&&&& //直接拼字符串
&&&&PreparedStatement ps = conn.prepareStatement(sql);
&&&&//ps.setInt(1, tie_id);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //占位符
&&&&if (ps.executeUpdate(sql)== 1) {
&&&&&flag =
&&&} catch (SQLException e) {
&&&&e.printStackTrace();
&&&} finally {
&&&&closeConn();
&public boolean UpdateMsg(String username, String nickname, String sex) {
&&boolean flag =
&&connect();
&&&String sql = &UPDATE tb_user SET username = ?, sex = ? WHERE user_id = ?&;
&&&PreparedStatement ps = conn.prepareStatement(sql);
&&&ps.setString(1, nickname);
&&&ps.setString(2, sex);
&&&ps.setString(3, username);
&&&if (ps.executeUpdate() == 1) {
&&&&flag =
&&} catch (SQLException e) {
&&&e.printStackTrace();
&&} finally {
&&&closeConn();
////////////会了简单增删改,还得会批量增删查改,这涉及到数据库事务的管理了,再批量增删查改时,如果是一条一条提交,然后在中间突然出现错误,后面的没有提交,这就会造成部分数据增删查改,部分没有执行,这肯定是不行的////////////////////
//批量删除的例子:前台传来一条用户账号组成的字符串,我们把他转换成整形数组,然后整形数组传进来
public boolean deletebyuser_ids(int ids[]) throws SQLException&&&& //出错回滚
&connect();
&&conn.setAutoCommit(false);&&& //设置手动提交
&&String sql=&delete from user_role where user_id=?;&;
&&PreparedStatement ps =& (PreparedStatement) conn.prepareStatement(sql);
&for(int i=0;i&ids.i++)
&&&ps.setInt(1, ids[i]);
&&&ps.addBatch();
//ps.addBatch(&sql语句&);&&&&&&&&&&&& //添加静态的sql语句
&&ps.executeBatch();
&&&&mit();&&&& //手动 提交
&&&} catch (SQLException e1) {
&&&&conn.rollback();&&&&&&&& //出错回滚
&catch (SQLException e) {
&&e.printStackTrace();
&&conn.setAutoCommit(true);&& //最后设为主动提交
//当然也可以使用拼接字符串的方式去执行批量删除
public boolean deleteall(int ids[])&&&&&&&&&&&& //拼接字符串方式删除
&connect();
&String sql=&delete from user_role where user_id in&;
&&String canshuc=&);&;
&&String canshua=&(&;
&&String canshub=&&;
&&for(int i=0;i&ids.i++)
&& canshub+=ids[i]+&,&;
&&canshub=canshub.substring(0, canshub.length()-1);
&&sql=sql+canshua+canshub+
&&PreparedStatement ps =& (PreparedStatement) conn.prepareStatement(sql);
&&int a=ps.executeUpdate();
&} catch (SQLException e) {
&&// TODO Auto-generated catch block
&&e.printStackTrace();
/////////////华丽分割线////////////
使用例子:仅仅在需要用到的地方填上
sqlDao sdo=new sqlDao();&&&&&&&&&&&&&&//创建对象
&&&boolean a=sdo.deletebyuser_id(user.getId());&&&&&&& //调用函数
&&&sdo.closeConn();&&&&&&&&&&&&&&&&&&&&&&&&&&&& //关闭连接
MYSQL总结完毕.
下面是jdbc对Oracle数据库的操作:需要oracle的jdbc操作包。
首先是连接数据库:
private static final String driverUrl = &oracle.jdbc.driver.OracleDriver&;
private static final String url = &jdbc:oracle:thin:@127.0.0.1:1521:myfirst&;
private static final String username = &XIAOHUA&;
private static final String password = &123456&;
public static Connection getConnection(){
Connection connection =
Class.forName(driverUrl);
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
然后是:基本的增删查改:
public static void main(String[] args) {
Connection connection = Helsd.getConnection();
String sql = &INSERT INTO T_ADD(RESOURCEID,NAME) VALUES(?,?)&;
PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1, &WENYSSSSssssssss&);
ps.setString(2, &B&);
if (ps.executeUpdate() == 1) {
System.out.println(&新增成功:&+connection);
catch (Exception e) {
System.out.print(e.getMessage());
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public static void main(String[] args) {
Connection connection = Helsd.getConnection();
String sqls = &delete from T_ADD where NAME=?&;
PreparedStatement pss = connection.prepareStatement(sqls);
pss.setString(1, &B&);
pss.execute();
catch (Exception e) {
System.out.print(e.getMessage());
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public static void main(String[] args) {
Connection connection = Helsd.getConnection();
String sqls = &select * from T_ADD where NAME=?&;
PreparedStatement pss = connection.prepareStatement(sqls);
pss.setString(1, &2&);
ResultSet rs= pss.executeQuery();
while(rs.next())
System.out.print(rs.getString(1));
System.out.print(rs.getString(2));
catch (Exception e) {
System.out.print(e.getMessage());
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public static void main(String[] args) {
Connection connection = Helsd.getConnection();
String sqls = &update T_ADD set NAME =? WHERE RESOURCEID=?&;
PreparedStatement pss = connection.prepareStatement(sqls);
pss.setString(1, &wenyan&);
pss.setString(2,&w&);
pss.execute();
catch (Exception e) {
System.out.print(e.getMessage());
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
存储过程:
存储过程语句:
第一种:只有IN参数的:
存储过程:
CREATE OR REPLACE
PROCEDURE INSERTADD(RESOURCES IN VARCHAR2,NAMES IN VARCHAR2) AS
INSERT INTO
T_ADD(RESOURCEID,NAME) VALUES(RESOURCES,NAMES);
public static void main(String[] args) {
Connection connection = Helsd.getConnection();
CallableStatement cs = connection.prepareCall(&{call insertadd(?,?)}&);
cs.setString(1, &资源1&);
cs.setString(2,&名称1&);
cs.execute(); //执行查询操作,并获取结果集
catch (Exception e) {
System.out.print(e.getMessage());
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
第二种:两个参数,第一个参数是传进来的RESOURCEID,第二个参数是输出,输出的是单个值
CREATE OR REPLACE
PROCEDURE getname(RESOURCEIDS IN VARCHAR2, NAMES OUT VARCHAR2)
select NAME INTO NAMES from T_ADD where RESOURCEID=RESOURCEIDS;
代码调用:
public static void main(String[] args) {
Connection connection = Helsd.getConnection();
CallableStatement cs = connection.prepareCall(&{call getname(?,?)}&);
cs.setString(1, &w&);
cs.registerOutParameter(2,java.sql.Types.VARCHAR);
cs.execute(); //执行查询操作,并获取结果集
String str= cs.getString(2);
System.out.print(str);
catch (Exception e) {
System.out.print(e.getMessage());
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
第三种:两种参数,输出的是表:通过先定义包,定义好类型CURSOR,程序拿到这个cursor装换成结果集拿出数据:
CREATE OR REPLACE
PACKAGE AA AS
TYPE TEST_CURSOR IS REF CURSOR;
建存储过程:
CREATE OR REPLACE
PROCEDURE GETLIST(p_name IN VARCHAR2,P_CUSER OUT AA.TEST_CURSOR) AS
OPEN P_CUSER FOR
SELECT * FROM T_ADD WHERE NAME=p_
jdbc调用然后拿数据:
public static void main(String[] args) {
Connection connection = Helsd.getConnection();
CallableStatement cs = connection.prepareCall(&{call getlist(?,?)}&);
cs.setString(1, &3&);
cs.registerOutParameter(2,OracleTypes.CURSOR);
cs.execute(); //执行查询操作,并获取结果集
ResultSet rs = (ResultSet) cs.getObject(2);
// 获取列名及类型
int colunmCount = rs.getMetaData().getColumnCount();
String[] colNameArr = new String[colunmCount];
String[] colTypeArr = new String[colunmCount];
for (int i = 0; i & colunmC i++) {
colNameArr[i] = rs.getMetaData().getColumnName(i + 1);
colTypeArr[i] = rs.getMetaData().getColumnTypeName(i + 1);
System.out.print(colNameArr[i] + &(& + colTypeArr[i] + &)&
System.out.println();
while (rs.next()) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i & colunmC i++) {
sb.append(rs.getString(i + 1) + & | &);
System.out.println(sb);
System.out.println(&------- Test Proc Out is ResultSet end. &);
catch (Exception e) {
System.out.print(e.getMessage());
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
第四种:输入输出IN&OUT
&输入输出都是它:
存储过程:
CREATE OR REPLACE
PROCEDURE testinout(p_name IN OUT VARCHAR2) AS
SELECT count(RESOURCEID) INTO p_name from T_ADD WHERE NAME=p_
// 测试Oracle连接是否成功
public static void main(String[] args) {
Connection connection = Helsd.getConnection();
CallableStatement cs = connection.prepareCall(&{call testinout(?)}&);
cs.setString(1, &3&);
cs.registerOutParameter(1,java.sql.Types.VARCHAR);
cs.execute(); //执行查询操作,并获取结果集
String str= cs.getString(1);
System.out.print(str);
catch (Exception e) {
System.out.print(e.getMessage());
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();

&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:35935次
排名:千里之外
原创:60篇
(1)(3)(2)(2)(1)(4)(4)(2)(2)(4)(5)(1)(6)(4)(5)(3)(1)(2)(2)(1)(1)(2)(4)

我要回帖

更多关于 无人机飞控师 的文章

 

随机推荐