首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

MySQL增多Sequence管理功能

2013-10-23 
MySQL增加Sequence管理功能public void testGetSequence() {Connection conn JDBCUtils.getConnection(u

MySQL增加Sequence管理功能
public void testGetSequence() {Connection conn = JDBCUtils.getConnection(url, userName, password);String sql = "SELECT CURRVAL('TestSeq');";PreparedStatement ptmt = null;ResultSet rs = null;try {ptmt = conn.prepareStatement(sql);rs = ptmt.executeQuery();int count = 0;while (rs.next()) {count = rs.getInt(1);}System.out.println(count);} catch (SQLException e) {e.printStackTrace();} finally {JDBCUtils.close(rs, ptmt, conn);}}

?

?

ps:在应用中,还有一种用java代码去实现模拟自增sequence的方式,具体思路是创建一张存放sequence的table,然后通过java调用sql语句去查询和修改这个table中指定sequence名称的值,这种方式请加上synchronized。具体代码这里就不上传了,因为实现了,未去测试过。

热点排行