List of usage examples for java.sql ResultSet close
void close() throws SQLException;
ResultSet
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. From source file:com.concursive.connect.web.modules.common.social.rating.dao.Rating.java
public static int queryObjectRatingCount(Connection db, int objectId, String table, String uniqueField) throws SQLException { int count = -1; PreparedStatement pst = db//www . jav a2s . c o m .prepareStatement("SELECT rating_count FROM " + table + " WHERE " + uniqueField + " = ? "); pst.setInt(1, objectId); ResultSet rs = pst.executeQuery(); if (rs.next()) { count = rs.getInt("rating_count"); } rs.close(); pst.close(); return count; }
From source file:com.concursive.connect.web.modules.common.social.rating.dao.Rating.java
public static int queryObjectRatingValue(Connection db, int objectId, String table, String uniqueField) throws SQLException { int count = -1; PreparedStatement pst = db/*from ww w . j a v a 2 s. com*/ .prepareStatement("SELECT rating_value FROM " + table + " " + "WHERE " + uniqueField + " = ? "); pst.setInt(1, objectId); ResultSet rs = pst.executeQuery(); if (rs.next()) { count = rs.getInt("rating_value"); } rs.close(); pst.close(); return count; }
From source file:com.concursive.connect.web.modules.common.social.rating.dao.Rating.java
public static int queryUserRating(Connection db, int userId, int objectId, String table, String uniqueField) throws SQLException { int existingVote = -1; PreparedStatement pst = db.prepareStatement( "SELECT rating FROM " + table + "_rating WHERE " + uniqueField + " = ? AND enteredby = ? "); pst.setInt(1, objectId);//from w w w . j a v a2s .co m pst.setInt(2, userId); ResultSet rs = pst.executeQuery(); if (rs.next()) { existingVote = rs.getInt("rating"); } rs.close(); pst.close(); return existingVote; }
From source file:dbutils.ExampleJDBC.java
/** * Unlike some other classes in DbUtils, this class(SqlNullCheckedResultSet) is NOT thread-safe. *//*from ww w . ja v a2s . co m*/ public static void findUseSqlNullCheckedResultSet() { Connection conn = getConnection(); try { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT id, name, gender, age, team_id as teamId FROM test_student"); SqlNullCheckedResultSet wrapper = new SqlNullCheckedResultSet(rs); wrapper.setNullString("N/A"); // Set null string rs = ProxyFactory.instance().createResultSet(wrapper); while (rs.next()) { System.out.println("id=" + rs.getInt("id") + " username=" + rs.getString("name") + " gender=" + rs.getString("gender")); } rs.close(); } catch (Exception e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } }
From source file:com.zimbra.cs.mailbox.util.MetadataDump.java
private static int getMailboxGroup(DbConnection conn, int mboxId) throws SQLException { int gid = 0;//from w ww. j a v a 2 s . c o m PreparedStatement stmt = null; ResultSet rs = null; try { stmt = conn.prepareStatement("SELECT group_id FROM mailbox WHERE id = ?"); stmt.setInt(1, mboxId); rs = stmt.executeQuery(); if (rs.next()) gid = rs.getInt(1); } finally { if (rs != null) rs.close(); if (stmt != null) stmt.close(); } return gid; }
From source file:com.concursive.connect.web.modules.setup.utils.SetupUtils.java
/** * Determines if the database schema has been created * * @param db// w w w. j av a2s. c o m * @return */ public static boolean isDatabaseInstalled(Connection db) { int count = -1; try { Statement st = db.createStatement(); ResultSet rs = st.executeQuery("SELECT count(*) AS recordcount " + "FROM database_version "); rs.next(); count = rs.getInt("recordcount"); rs.close(); st.close(); } catch (Exception e) { } return count > 0; }
From source file:local.Statistics.LessSellCars.java
/** * @param args the command line arguments *///from w w w . ja v a 2 s . c o m public static void carrosMenosVendidos() { Graficas_DAO gr = new Graficas_DAO(); ResultSet rs = gr.getgraficaautomas(); try { String nameAuto; int quantitySales; DefaultPieDataset data = new DefaultPieDataset(); while (rs.next()) { nameAuto = rs.getString(3); quantitySales = rs.getInt(1); data.setValue(nameAuto, quantitySales); } JFreeChart chart = ChartFactory.createPieChart("GRAFICAS AUTOS MENOS VENDIDOS", data, true, true, false); ChartFrame frame = new ChartFrame("Autos menos vendidos", chart); frame.pack(); frame.setVisible(true); rs.close(); gr.close(); } catch (SQLException ex) { Logger.getLogger(LessSellCars.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:application.bbdd.pool.java
public static void realizaConsulta1() { Connection conexion = null;//from w w w .j a v a 2s .c om Statement sentencia = null; ResultSet rs = null; try { // BasicDataSource nos reserva una conexion y nos la devuelve conexion = getConexion(); sentencia = conexion.createStatement(); rs = sentencia.executeQuery("select count(*) from user"); rs.next(); JOptionPane.showMessageDialog(null, "El numero de usuarios es: " + rs.getInt(1)); logStatistics(); } catch (SQLException e) { JOptionPane.showMessageDialog(null, e.toString()); } finally { try { rs.close(); sentencia.close(); liberaConexion(conexion); } catch (Exception fe) { JOptionPane.showMessageDialog(null, fe.toString()); } } }
From source file:local.Statistics.LessSellRepuesto.java
/** * @param args the command line arguments *//*from w w w . ja v a 2 s . c om*/ public static void repuestosMenosVendidos() { Graficas_DAO gr = new Graficas_DAO(); //obtencion de datos ResultSet rs = gr.getgraficarepuestomen(); try { String nameAuto; int quantitySales; DefaultPieDataset data = new DefaultPieDataset(); while (rs.next()) { nameAuto = rs.getString(3); quantitySales = rs.getInt(1); data.setValue(nameAuto, quantitySales); } JFreeChart chart = ChartFactory.createPieChart("GRAFICAS REPUESTO MENOS VENDIDOS", data, true, true, false); ChartFrame frame = new ChartFrame("Repuestos menos vendidos", chart); frame.pack(); frame.setVisible(true); rs.close(); gr.close(); } catch (SQLException ex) { Logger.getLogger(LessSellRepuesto.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.chaosinmotion.securechat.server.commands.GetMessages.java
public static ReturnResult processRequest(Login.UserInfo userinfo, JSONObject requestParams) throws ClassNotFoundException, SQLException, IOException { String deviceid = requestParams.optString("deviceid"); MessageReturnResult mrr = new MessageReturnResult(); /*//from w w w . ja v a 2 s. c o m * Save message to the database. */ Connection c = null; PreparedStatement ps = null; ResultSet rs = null; try { /* * Get the device ID for this device. Verify it belongs to the * user specified */ c = Database.get(); ps = c.prepareStatement("SELECT deviceid " + "FROM Devices " + "WHERE deviceuuid = ? AND userid = ?"); ps.setString(1, deviceid); ps.setInt(2, userinfo.getUserID()); rs = ps.executeQuery(); int deviceID = 0; if (rs.next()) { deviceID = rs.getInt(1); } rs.close(); ps.close(); if (deviceID == 0) { return new ReturnResult(Errors.ERROR_UNKNOWNDEVICE, "Unknown device"); } /* * Run query to get messages */ ps = c.prepareStatement("SELECT Messages.messageid, " + " Messages.senderid, " + " Users.username, " + " Messages.toflag, " + " Messages.received, " + " Messages.message " + "FROM Messages, Users " + "WHERE Messages.deviceid = ? " + " AND Messages.senderid = Users.userid"); ps.setInt(1, deviceID); rs = ps.executeQuery(); while (rs.next()) { int messageID = rs.getInt(1); int senderID = rs.getInt(2); String senderName = rs.getString(3); boolean toflag = rs.getBoolean(4); Timestamp received = rs.getTimestamp(5); byte[] message = rs.getBytes(6); mrr.addMessage(messageID, senderID, senderName, toflag, received, message); } /* * Return messages */ return mrr; } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (c != null) c.close(); } }