码迷,mamicode.com
首页 > 数据库 > 详细

java调用oracle函数

时间:2015-06-11 16:58:48      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

/**
	 * 调用函数取得数据表的ID值 
	 * @param tableName 表名
	 * @return
	 * @throws SQLException
	 */
	public String callFun(String tableName) throws SQLException {
		Connection conn = ConnectionFactory.getConnection();
		CallableStatement cstmt = null;
		cstmt = conn.prepareCall("{?=call getIdBySeq(?)}");
		cstmt.registerOutParameter(1, Types.VARCHAR);
		cstmt.setString(2, tableName);
		cstmt.execute();
		return cstmt.getString(1);
	}

public class ConnectionFactory {

	private ConnectionFactory() {
	}

	private static ComboPooledDataSource ds = null;

	public static synchronized Connection getConnection() {   
        Connection con = null;   
        ds = new ComboPooledDataSource();
        try {   
            con = ds.getConnection();   
        } catch (SQLException e1) {   
            e1.printStackTrace();   
        }   
        return con;   
    }   
}


java调用oracle函数

标签:

原文地址:http://blog.csdn.net/xiongwt/article/details/46458083

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!