Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: gsoft/util/NextNum.java


1   /*************************************************************************
2   Copyright (C) 2003  Steve Gee
3   stevesgee@cox.net
4   
5   This program is free software; you can redistribute it and/or
6   modify it under the terms of the GNU General Public License
7   as published by the Free Software Foundation; either version 2
8   of the License, or (at your option) any later version.
9   
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *************************************************************************/
19  
20  package gsoft.util;
21  import java.sql.*;
22  
23  public class NextNum implements java.io.Serializable{
24    public static synchronized int getNextNum(Statement stmt, String type) throws Exception{
25      int nextnum = (-1);
26      ResultSet rs = stmt.executeQuery("select nextnum"
27        +" from nextnum"
28        +" where type = '" + type + "'");
29      if (rs.next()) {
30        nextnum = rs.getInt(1);
31        int newNextNum = nextnum + 1;
32        stmt.executeUpdate("update nextnum set nextnum = " + newNextNum + " where type = '" + type + "'");
33        stmt.execute("commit");
34      }//end if
35      rs.close();
36      return nextnum;
37    }//end getNextNum
38  
39  
40    public static synchronized int getNextNum(Statement stmt, String table, int rowskip) throws Exception {
41      ResultSet rset = stmt.executeQuery("select nextnum "
42        +" from nextnum"
43        +" where type = '" + table.trim() + "'");
44      rset.next();
45      int nextnum = rset.getInt("nextnum");
46      rset.close();
47      stmt.executeUpdate("update nextnum"
48        +" set nextnum = " + (nextnum + rowskip)
49        +" where type = '" + table.trim() + "'");
50      return nextnum;
51    }
52  
53  
54  }