public void updateServiceType( CFSecurityAuthorization Authorization, CFSecurityServiceTypeBuff Buff) { final String S_ProcName = "updateServiceType"; ResultSet resultSet = null; try { int ServiceTypeId = Buff.getRequiredServiceTypeId(); String Description = Buff.getRequiredDescription(); int Revision = Buff.getRequiredRevision(); Connection cnx = schema.getCnx(); String sql = "exec sp_update_svctype ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"; if (stmtUpdateByPKey == null) { stmtUpdateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtUpdateByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtUpdateByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtUpdateByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtUpdateByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtUpdateByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtUpdateByPKey.setString(argIdx++, "SVCT"); stmtUpdateByPKey.setInt(argIdx++, ServiceTypeId); stmtUpdateByPKey.setString(argIdx++, Description); stmtUpdateByPKey.setInt(argIdx++, Revision); resultSet = stmtUpdateByPKey.executeQuery(); if (resultSet.next()) { CFSecurityServiceTypeBuff updatedBuff = unpackServiceTypeResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredDescription(updatedBuff.getRequiredDescription()); Buff.setRequiredRevision(updatedBuff.getRequiredRevision()); } else { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
public int[] getAd() { int i = 0; int j = 0; int[] ans = null; String str = "SELECT * FROM ad ORDER BY id"; try { row = stm.executeQuery(str); row.last(); i = row.getRow(); row.first(); ans = new int[i + 1]; if (i > 0) { ans[0] = i; do { j++; ans[j] = Integer.parseInt(row.getString("priority")); } while (row.next()); } else { ans[0] = 0; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ans; }
/** * Function: Attempt to login the user. * * <p>Param: stmt - Statement object to run select. * * <p>Return: True if the credentials are correct. * * <p>schwehr 20100310 */ private static boolean login(Statement stmt) { String pass; System.out.print("E-mail: "); Main.user = Keyboard.in.readString(); System.out.print("Password: "******"select email, pwd from users where email ='%s' and pwd ='%s'", Main.user, pass); ResultSet rset = stmt.executeQuery(query); // There should only be one record found if the credentials are valid.. rset.last(); if (rset.getRow() == 1) { return true; } } catch (SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); } return false; }
public String[] getVideo() { int i = 0; int j = 0; String[] ans = null; String str = "SELECT * FROM video ORDER BY id"; try { row = stm.executeQuery(str); row.last(); i = row.getRow(); row.first(); ans = new String[i + 1]; if (i > 0) { ans[0] = Integer.toString(i); do { j++; ans[j] = row.getString("name"); } while (row.next()); } else { ans[0] = "0"; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ans; }
public ArrayList<Orientacao> getBy(String SQL) { Connection conn = new Conn().getConnection(); ArrayList<Orientacao> lo = new ArrayList<Orientacao>(); try { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(SQL); Orientacao o = new Orientacao(); while (rs.next()) { o.setAluno_id(rs.getInt("aluno_id")); o.setProfessor_id(rs.getInt("professor_id")); o.setAno(rs.getInt("ano")); lo.add(o); } rs.last(); } catch (SQLException e) { System.out.println("Erro no SQL"); } return lo; }
/** * Attempts to add a new shipment to the table * * @param dto - the shipment to add to the database * @return boolean value for whether the shipment was added */ public boolean newShipment(ShipmentDTO dto) { boolean success; String sqlQ = "INSERT INTO gunnargo_cmsc495.Shipment SET " + "ItemID = '" + dto.getItemID() + "', " + "CustID = '" + dto.getCustID() + "', " + "Destination = '" + dto.getDestination() + "', " + "Weight = '" + dto.getWeight() + "', " + "NumItems = '" + dto.getNumItems() + "';"; try { con = DriverManager.getConnection(url, userid, password); Statement stmt = con.createStatement(); stmt.execute(sqlQ); ResultSet rs = stmt.executeQuery("SELECT * FROM gunnargo_cmsc495.Shipment"); if (rs.last()) dto.setShipID(rs.getString("ShipID")); success = !dto.getShipID().equals(""); con.close(); } catch (SQLException ex) { System.out.println(ex.getMessage()); success = false; } return success; }
public void testTemp() throws Exception { Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt.execute("CREATE TABLE #temp ( pk INT PRIMARY KEY, f_string VARCHAR(30), f_float FLOAT )"); // populate in the traditional way for (int i = 0; i < 100; i++) { stmt.execute( "INSERT INTO #temp " + "VALUES( " + i + "," + "'The String " + i + "'" + ", " + i + ")"); } dump(stmt.executeQuery("SELECT Count(*) FROM #temp")); // Navigate around ResultSet rs = stmt.executeQuery("SELECT * FROM #temp"); rs.first(); dumpRow(rs); rs.last(); dumpRow(rs); rs.first(); dumpRow(rs); stmt.execute("DROP TABLE #temp"); stmt.close(); }
private void GenerateAdminNoActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_GenerateAdminNoActionPerformed int IntAdminNo = 0; String prodID; try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/VunaFeeds", "root", ""); Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery("Select * from product where Status = 'Active'"); if (rs.last()) { String adminNo = rs.getString("ProductID"); IntAdminNo = Integer.valueOf(adminNo); System.out.println(IntAdminNo); IntAdminNo++; prodID = String.valueOf(IntAdminNo); ProductID.setText(prodID); } else { IntAdminNo = 1; prodID = String.valueOf(IntAdminNo); ProductID.setText(prodID); } ProductID.setEditable(false); } catch (SQLException e) { System.out.println("2 Error : " + e); JOptionPane.showMessageDialog(null, "Oops!! An error occured. \n " + e); } catch (Exception ex) { System.out.println("Error 1:" + ex); JOptionPane.showMessageDialog(null, "Oops!! An error occured. \n" + ex); } } // GEN-LAST:event_GenerateAdminNoActionPerformed
public int[] searchVideo(String key) { int i = 0; int j = 0; int[] ans = null; String str = "SELECT * FROM video WHERE name LIKE '%" + key + "%'"; try { row = stm.executeQuery(str); row.last(); i = row.getRow(); row.first(); if (i == 0) { ans = new int[1]; } else { ans = new int[i]; } if (i > 0) { do { ans[j] = Integer.parseInt(row.getString("id")); j++; } while (row.next()); } else { ans[0] = 0; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ans; }
public CFCrmContactTagBuff readBuff( CFSecurityAuthorization Authorization, CFCrmContactTagPKey PKey) { final String S_ProcName = "readBuff"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory() .newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); long TenantId = PKey.getRequiredTenantId(); long ContactId = PKey.getRequiredContactId(); long TagId = PKey.getRequiredTagId(); String sql = "{ call sp_read_ctc_tag( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + " ) }"; if (stmtReadBuffByPKey == null) { stmtReadBuffByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffByPKey.setLong(argIdx++, TenantId); stmtReadBuffByPKey.setLong(argIdx++, ContactId); stmtReadBuffByPKey.setLong(argIdx++, TagId); resultSet = stmtReadBuffByPKey.executeQuery(); if ((resultSet != null) && resultSet.next()) { CFCrmContactTagBuff buff = unpackContactTagResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } return (buff); } else { return (null); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
private void Baru() { btnSave.setText("Save"); txtNip.requestFocus(); txtNip.setText(""); try { Class.forName(KoneksiDatabase.driver); java.sql.Connection c = DriverManager.getConnection( KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass); Statement s = c.createStatement(); String sql = "select * from absensi_lembur"; ResultSet rs = s.executeQuery(sql); final String[] headers = { "Kd Absen", "NIP", "Tgl Absen", "Masuk", "Pulang", "Hari", "Tipe Hari", "Terlambat", "Lembur", "Tipe Lembur", "Tot Lembur", "Tunj Makan", "Tunj Transport" }; rs.last(); int n = rs.getRow(); Object[][] data = new Object[n][13]; int p = 0; rs.beforeFirst(); while (rs.next()) { data[p][0] = rs.getString(1); data[p][1] = rs.getString(2); data[p][2] = rs.getString(3); data[p][3] = rs.getString(4); data[p][4] = rs.getString(5); data[p][5] = rs.getString(6); data[p][6] = rs.getString(7); data[p][7] = rs.getString(8); data[p][8] = rs.getString(9); data[p][9] = rs.getString(10); data[p][10] = rs.getString(11); data[p][11] = rs.getString(12); data[p][12] = rs.getString(13); p++; } tblLembur.setModel(new DefaultTableModel(data, headers)); tblLembur.setAlignmentX(CENTER_ALIGNMENT); } catch (Exception e) { JOptionPane.showMessageDialog( null, "Gagal Koneksi, Ada Kesalahan.", "Warning", JOptionPane.WARNING_MESSAGE); } }
public CFInternetTopDomainBuff readBuffByNameIdx( CFSecurityAuthorization Authorization, long TenantId, long TldId, String Name) { final String S_ProcName = "readBuffByNameIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_read_tdomdef_by_nameidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + " )"; if (stmtReadBuffByNameIdx == null) { stmtReadBuffByNameIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByNameIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByNameIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByNameIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByNameIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByNameIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffByNameIdx.setLong(argIdx++, TenantId); stmtReadBuffByNameIdx.setLong(argIdx++, TldId); stmtReadBuffByNameIdx.setString(argIdx++, Name); resultSet = stmtReadBuffByNameIdx.executeQuery(); if (resultSet.next()) { CFInternetTopDomainBuff buff = unpackTopDomainResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } return (buff); } else { return (null); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
/* * Execute query against a list of sensors * * */ public static String executeQuery( String envelope, String query, String matchingSensors, String format) throws ParseException { // String matchingSensors = getListOfSensorsAsString(envelope); String reformattedQuery = reformatQuery(query, matchingSensors); StringBuilder sb = new StringBuilder(); Connection connection = null; try { connection = Main.getDefaultStorage().getConnection(); Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet results = statement.executeQuery(reformattedQuery); ResultSetMetaData metaData; // Additional information about the results int numCols, numRows; // How many rows and columns in the table metaData = results.getMetaData(); // Get metadata on them numCols = metaData.getColumnCount(); // How many columns? results.last(); // Move to last row numRows = results.getRow(); // How many rows? String s; // System.out.println("* Executing query *\n" + reformattedQuery + "\n***"); // headers // sb.append("# Query: " + query + NEWLINE); sb.append("# Query: " + reformattedQuery.replaceAll("\n", "\n# ") + NEWLINE); sb.append("# "); // System.out.println("ncols: " + numCols); // System.out.println("nrows: " + numRows); for (int col = 0; col < numCols; col++) { sb.append(metaData.getColumnLabel(col + 1)); if (col < numCols - 1) sb.append(SEPARATOR); } sb.append(NEWLINE); for (int row = 0; row < numRows; row++) { results.absolute(row + 1); // Go to the specified row for (int col = 0; col < numCols; col++) { Object o = results.getObject(col + 1); // Get value of the column // logger.warn(row + " , "+col+" : "+ o.toString()); if (o == null) s = "null"; else s = o.toString(); if (col < numCols - 1) sb.append(s).append(SEPARATOR); else sb.append(s); } sb.append(NEWLINE); } } catch (SQLException e) { sb.append("ERROR in execution of query: " + e.getMessage()); } finally { Main.getDefaultStorage().close(connection); } return sb.toString(); }
public void deleteTopDomain(CFSecurityAuthorization Authorization, CFInternetTopDomainBuff Buff) { final String S_ProcName = "deleteTopDomain"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); long TenantId = Buff.getRequiredTenantId(); long Id = Buff.getRequiredId(); final String sql = "CALL sp_delete_tdomdef( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + " )"; if (stmtDeleteByPKey == null) { stmtDeleteByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByPKey.setLong(argIdx++, TenantId); stmtDeleteByPKey.setLong(argIdx++, Id); stmtDeleteByPKey.setInt(argIdx++, Buff.getRequiredRevision()); ; resultSet = stmtDeleteByPKey.executeQuery(); if (resultSet.next()) { int deleteFlag = resultSet.getInt(1); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } } else { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
public void connectItems(String query) // PRE: query must be initialized // POST: Updates the list of Items based on the query. { String driver = "org.apache.derby.jdbc.ClientDriver"; // Driver for DB String url = "jdbc:derby://localhost:1527/ShopDataBase"; // Url for DB String user = "******"; // Username for db String pass = "******"; // Password for db Connection myConnection; // Connection obj to db Statement stmt; // Statement to execute a result appon ResultSet results; // A set containing the returned results int rowcount; // Num objects in the resultSet int i; // Index for the array try { // Try connection to db Class.forName(driver).newInstance(); // Create our db driver myConnection = DriverManager.getConnection(url, user, pass); // Initalize our connection stmt = myConnection.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); // Create a new statement results = stmt.executeQuery(query); // Store the results of our query rowcount = 0; if (results.last()) // Go to the last result { rowcount = results.getRow(); results.beforeFirst(); } itemsArray = new Item[rowcount]; i = 0; while (results.next()) // Itterate through the results set { itemsArray[i] = new Item( results.getInt("item_id"), results.getString("item_name"), results.getString("item_type"), results.getInt("price"), results.getInt("owner_id"), results.getString("item_path")); // Creat new Item i++; } results.close(); // Close the ResultSet stmt.close(); // Close the statement myConnection.close(); // Close the connection to db } catch (Exception e) // Cannot connect to db { System.err.println(e.toString()); System.err.println("Error, something went horribly wrong in connectItems!"); } }
public CFSecurityISOCountryCurrencyBuff lockBuff( CFSecurityAuthorization Authorization, CFSecurityISOCountryCurrencyPKey PKey) { final String S_ProcName = "lockBuff"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory() .newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); short ISOCountryId = PKey.getRequiredISOCountryId(); short ISOCurrencyId = PKey.getRequiredISOCurrencyId(); final String sql = "CALL sp_lock_iso_cntryccy( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )"; if (stmtLockBuffByPKey == null) { stmtLockBuffByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtLockBuffByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtLockBuffByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtLockBuffByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtLockBuffByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtLockBuffByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtLockBuffByPKey.setShort(argIdx++, ISOCountryId); stmtLockBuffByPKey.setShort(argIdx++, ISOCurrencyId); resultSet = stmtLockBuffByPKey.executeQuery(); if (resultSet.next()) { CFSecurityISOCountryCurrencyBuff buff = unpackISOCountryCurrencyResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } return (buff); } else { return (null); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
public void deleteURLProtocolByIsSecureIdx( CFSecurityAuthorization Authorization, boolean argIsSecure) { final String S_ProcName = "deleteURLProtocolByIsSecureIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_delete_urlproto_by_issecureidx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtDeleteByIsSecureIdx == null) { stmtDeleteByIsSecureIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByIsSecureIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIsSecureIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByIsSecureIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByIsSecureIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIsSecureIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); if (argIsSecure) { stmtDeleteByIsSecureIdx.setString(argIdx++, "Y"); } else { stmtDeleteByIsSecureIdx.setString(argIdx++, "N"); } resultSet = stmtDeleteByIsSecureIdx.executeQuery(); if (resultSet.next()) { int deleteFlag = resultSet.getInt(1); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } } else { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
/** Test of insert method, of class Flight. */ @Test public void testInsert() throws Exception { f1.insert(db); ResultSet rs = db.execute("SELECT * FROM Flights ORDER BY id ASC"); rs.last(); assertEquals(rs.getString("startdestination"), "Copenhagen"); assertEquals(rs.getString("enddestination"), "London"); assertEquals(rs.getInt("numberofseats"), 100); assertEquals(rs.getString("timestamp"), "14:00"); }
public Integer end_new_record() { if (error) return 0; else try { results.insertRow(); results.last(); return results.getInt(current_table + "_id"); } catch (Exception ex) { throw new InvalidQueryException("Database update failed"); } }
public CFSecurityHostNodeBuff readBuffByUDescrIdx( CFSecurityAuthorization Authorization, long ClusterId, String Description) { final String S_ProcName = "readBuffByUDescrIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "{ call sp_read_hostnode_by_udescridx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " ) }"; if (stmtReadBuffByUDescrIdx == null) { stmtReadBuffByUDescrIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByUDescrIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByUDescrIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByUDescrIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByUDescrIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByUDescrIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffByUDescrIdx.setLong(argIdx++, ClusterId); stmtReadBuffByUDescrIdx.setString(argIdx++, Description); resultSet = stmtReadBuffByUDescrIdx.executeQuery(); if ((resultSet != null) && resultSet.next()) { CFSecurityHostNodeBuff buff = unpackHostNodeResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } return (buff); } else { return (null); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
public void readData() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection( "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" + filep); stmnt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); rst = con.getMetaData().getTables(null, null, "%", null); rst.next(); String SheetName = rst.getString(3); String query = "Select distinct * from [" + SheetName + "]"; rs = stmnt.executeQuery(query); if (rs != null) { rs.last(); RowCount = rs.getRow(); rs.beforeFirst(); // stmnt.close(); rst.close(); if (RowCount > 0) { registno = new String[RowCount]; name = new String[RowCount]; kdno = new int[RowCount]; kcno = new double[RowCount]; ccno = new double[RowCount]; seat = new double[RowCount]; i = 0; while (rs.next() && (rs.getString(1) != null)) { // rs.next(); i++; try { registno[i] = rs.getString(1); name[i] = rs.getString(2); kdno[i] = Integer.parseInt(rs.getString(3)); kcno[i] = Double.parseDouble(rs.getString(4)); ccno[i] = Double.parseDouble(rs.getString(5)); seat[i] = Double.parseDouble(rs.getString(6)); System.out.println(i); } catch (Exception e) { e.printStackTrace(); } } } } rs.close(); con.close(); } catch (Exception e) { // System.out.println("fail to get student connection"); } }
public int applyParamsToInsertAndUpdateStatement( PreparedStatement pstmt, TemporalEntity sde, Date transactionTime, Date createdTime) throws Exception { int idx = applyParamsToInsertStatement(pstmt, sde, transactionTime, createdTime); currentRS.last(); for (String notUpdateName : notUpdatedColumns) { Object o = currentRS.getObject(notUpdateName); pstmt.setObject(idx++, o); } return idx; }
public static boolean checkForTables(Configuration config) { String sqlCheck = "SHOW TABLES"; try (Connection connection = Database.getConnection(config); PreparedStatement preparedStatement = connection.prepareStatement(sqlCheck); ResultSet res = preparedStatement.executeQuery()) { res.last(); if (res.getRow() != 3) { return false; } } catch (SQLException e) { e.printStackTrace(); return false; } return true; }
/** 为借用 查询所有记录 */ public String[][] searchAllForUse() { Database DB = new Database(); AssetsBean aBean = new AssetsBean(); PersonBean pBean = new PersonBean(); String[][] sn = null; int row = 0; int i = 0; sql = "select * from AssetsTrjn where FromAcc ='设备借用' order by JourNo"; try { DB.OpenConn(); rs = DB.executeQuery(sql); if (rs.last()) { row = rs.getRow(); } if (row == 0) { sn = new String[1][6]; sn[0][0] = " "; sn[0][1] = " "; sn[0][2] = " "; sn[0][3] = " "; sn[0][4] = " "; sn[0][5] = " "; } else { sn = new String[row][6]; rs.first(); rs.previous(); while (rs.next()) { sn[i][0] = rs.getString("JourNo"); sn[i][1] = aBean.getAssetsName(rs.getString("AssetsID")); sn[i][2] = rs.getString("RegDate"); sn[i][3] = pBean.getPersonName(rs.getString("PersonID")); sn[i][4] = rs.getString("Use"); sn[i][5] = rs.getString("Other"); i++; } } } catch (Exception e) { } finally { DB.closeStmt(); DB.closeConn(); } return sn; }
public SingleNameReport(WritableWorkbook workbook, Statement new_statement, String[] arguments) { String main_tsn = ""; String main_rank = ""; String main_kingdom = ""; row = 0; try { statement = new_statement; func = new AdditionalFunctions(statement); copy = workbook; kingdom = arguments[0]; hrank = arguments[1]; lrank = arguments[2]; scientificName = arguments[3]; date_from = arguments[4]; date_to = arguments[5]; user = arguments[6]; String temp = ""; temp = "SELECT tsn,rank_id,kingdom_id from Tree where scientificName='" + scientificName + "'"; System.out.println(temp); result = statement.executeQuery(temp); metadata = result.getMetaData(); int numberOfRows = 0; int hrankVal = Integer.parseInt(hrank); int main_rankVal = 0; if (result.last()) numberOfRows = result.getRow(); result.first(); if (numberOfRows > 0 && metadata.getColumnCount() > 0) { main_tsn = result.getString(1); main_rank = result.getString(2); main_rankVal = Integer.parseInt(main_rank); main_kingdom = result.getString(3); } if (HasChildren(main_tsn) == true) FindChildInformation(main_tsn, arguments, func); FileInFrontPage frontPage = new FileInFrontPage(copy, statement, arguments); copy.write(); copy.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } // end of constructor
/** * This method is called from within the constructor to initialize the form. WARNING: Do NOT * modify this code. The content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") void acceder(String usuario, String pass) { // String cap=""; String sql = "SELECT * FROM login WHERE usuario='" + usuario + "' && password='******'"; try { Statement st = cn.createStatement(); ResultSet rs = st.executeQuery(sql); rs.last(); // recuperamos el numero de registros del Resulset int encontrado = rs.getRow(); if ("".equals(txtusuario.getText()) || "".equals(txtcontra.getPassword())) { JOptionPane.showMessageDialog( null, "Rellene Todos los Campos", "Campos Vacios", JOptionPane.INFORMATION_MESSAGE); } else { if (encontrado == 1) // si nos devuelve un registro significa que la autenticacion es correcta y // mostramos el formulario { JOptionPane.showMessageDialog( null, "Bienvenido\n" + "Has ingresado satisfactoriamente al sistema", "Ingreso Exitoso!", JOptionPane.INFORMATION_MESSAGE); Principal prin = new Principal(); prin.setVisible(true); dispose(); } else { JOptionPane.showMessageDialog( null, "Ingreso de Datos Incorrectos", "Usuario ó Contraseña Incorrecta", javax.swing.JOptionPane.ERROR_MESSAGE); } // cerramos la conexion rs.close(); st.close(); } } catch (Exception e) { e.printStackTrace(); } }
private boolean isLoggedIn(int id) { boolean isLoggedIn = false; Connection con = getConnect(); int personId = getPersonId(id); try { String SQL = "SELECT * FROM LogInOut WHERE personId = " + personId + " AND TimeOut IS NULL"; Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(SQL); if (rs != null && rs.next()) { rs.last(); isLoggedIn = true; } } catch (Exception err) { MessageBox.infoBox(err.toString(), "Error from isLoggedIn"); System.out.println(err); } closeConnect(); return isLoggedIn; // SELECT * FROM LogInOut WHERE personId = 1 AND TimeOut IS NULL }
// public method that checks for existance of children public boolean HasChildren(String tsn) { String temp = "SELECT tsn from Tree where parent_tsn='" + tsn + "'"; if (lrank.compareTo("0") != 0 && lrank.compareTo("7") != 0) temp = temp + " AND rank_id<=" + lrank; System.out.println(temp); int numberOfRows = 0; boolean flag = false; try { result = statement.executeQuery(temp); metadata = result.getMetaData(); if (result.last()) numberOfRows = result.getRow(); result.first(); if (numberOfRows > 0 && metadata.getColumnCount() > 0) flag = true; } catch (SQLException sql) { sql.printStackTrace(); System.exit(1); } return flag; } // end of method HasChildren
/** Test of delete method, of class Flight. */ @Test public void testDelete() throws Exception { System.out.println("delete"); ResultSet rs = db.execute("SELECT * FROM Flights"); rs.last(); int id = rs.getInt("id"); rs.close(); ResultSet rs2 = db.execute("SELECT COUNT(*) AS rowcount FROM Flights"); rs2.next(); int rc = rs2.getInt("rowcount"); rs2.close(); f1.delete(db, id); ResultSet rs3 = db.execute("SELECT COUNT(*) AS rowcount2 FROM Flights"); rs3.next(); int rc2 = rs3.getInt("rowcount2"); assertEquals(rc - 1, rc2); }
public synchronized void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { HttpSession dbSession = request.getSession(); JspFactory _jspxFactory = JspFactory.getDefaultFactory(); PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true); ServletContext dbApplication = dbSession.getServletContext(); nseer_db_backup1 stock_db = new nseer_db_backup1(dbApplication); try { if (stock_db.conn((String) dbSession.getAttribute("unit_db_name"))) { int i; int intRowCount; String sqll = "select * from stock_config_public_char where describe1='\u51fa\u5165\u5e93\u7406\u7531'"; ResultSet rs = stock_db.executeQuery(sqll); rs.next(); rs.last(); intRowCount = rs.getRow(); String[] del = new String[intRowCount]; del = (String[]) dbSession.getAttribute("del"); if (del != null) { for (i = 1; i <= intRowCount; i++) { String sql = "delete from stock_config_public_char where id='" + del[i - 1] + "'"; stock_db.executeUpdate(sql); } } stock_db.commit(); stock_db.close(); response.sendRedirect("stock/config/apply_gather_pay/reason.jsp"); } else { response.sendRedirect("error_conn.htm"); } } catch (Exception ex) { ex.printStackTrace(); } }