Here you can find the source of runInsertLong(PreparedStatement s)
Parameter | Description |
---|---|
s | a prepared statement that provides a return value |
protected static long runInsertLong(PreparedStatement s)
//package com.java2s; /*/*from www. java2 s . co m*/ collabREate Utils Copyright (C) 2008 Chris Eagle <cseagle at gmail d0t com> Copyright (C) 2008 Tim Vidas <tvidas at gmail d0t com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.sql.*; public class Main { /** * runInsertLong is a database insert helper function, it runs an insert and returns * a Long value based on the result of the query - Statements must return a value to * be used with this function * @param s a prepared statement that provides a return value * @return long return of the insert query */ protected static long runInsertLong(PreparedStatement s) { long rval = -1; try { ResultSet rs = s.executeQuery(); if (rs.next()) { rval = rs.getLong(1); System.out.println("SQL Insert rval: " + rval); } rs.close(); } catch (SQLException e) { System.err.println("SQL Exception encountered"); System.err.println(e); } catch (Exception exc) { System.err .println("Database Insert error: " + exc.getMessage()); exc.printStackTrace(); } return rval; } }