Example usage for java.sql PreparedStatement setDouble

List of usage examples for java.sql PreparedStatement setDouble

Introduction

In this page you can find the example usage for java.sql PreparedStatement setDouble.

Prototype

void setDouble(int parameterIndex, double x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java double value.

Usage

From source file:nl.tudelft.stocktrader.derby.DerbyOrderDAO.java

public void updateHolding(int holdingId, double quantity) throws DAOException {
    if (logger.isDebugEnabled()) {
        logger.debug("OrderDAO.updateHolding()\nHolding ID :" + holdingId + "\nQuantity :" + quantity);
    }//from w ww  .j  ava2 s .  c o m

    PreparedStatement updateHoldingStat = null;
    try {
        updateHoldingStat = sqlConnection.prepareStatement(SQL_UPDATE_HOLDING);
        updateHoldingStat.setDouble(1, quantity);
        updateHoldingStat.setInt(2, holdingId);
        updateHoldingStat.executeUpdate();

    } catch (SQLException e) {
        throw new DAOException("An exception is thrown during an updation of holding entry", e);
    } finally {
        if (updateHoldingStat != null) {
            try {
                updateHoldingStat.close();
            } catch (Exception e) {
                logger.debug("", e);
            }
        }
    }
}

From source file:pack1.test.java

@WebMethod(operationName = "convert")
public String convert(@WebParam(name = "encodedImageStr") String encodedImageStr,
        @WebParam(name = "fileName") String fileName, @WebParam(name = "AOR") String AOR,
        @WebParam(name = "val") int value) {
    System.out.println("Value" + value);
    FileOutputStream imageOutFile = null;
    try {//from   w w  w. j a v  a 2  s  .co m
        Connection con, con1;
        Statement stmtnew = null;
        area = Double.parseDouble(AOR);
        //int val=Integer.parseInt(value);
        System.out.println("connecting");
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        System.out.println("connected");
        con = DriverManager.getConnection("jdbc:odbc:test");
        System.out.println(" driver loaded in connection.jsp");
        stmtnew = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        // Decode String using Base64 Class
        byte[] imageByteArray = encodedImageStr.getBytes();
        // Write Image into File system - Make sure you update the path
        imageOutFile = new FileOutputStream(
                "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/cropped" + fileName);
        imageOutFile.write(imageByteArray);
        imageOutFile.close();
        System.out.println("Image Successfully Stored");
        FileInputStream leafPicPath = new FileInputStream(
                "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/cropped" + fileName);
        BufferedImage cat;
        int height, width;
        cat = ImageIO.read(leafPicPath);
        height = cat.getHeight();
        width = cat.getWidth();
        for (int w = 0; w < cat.getWidth(); w++) {

            for (int h = 0; h < cat.getHeight(); h++) {
                // BufferedImage.getRGB() saves the colour of the pixel as a single integer.
                // use Color(int) to grab the RGB values individually.

                Color color = new Color(cat.getRGB(w, h));

                // use the RGB values to get their average.

                int averageColor = ((color.getRed() + color.getGreen() + color.getBlue()) / 3);
                // create a new Color object using the average colour as the red, green and blue

                // colour values

                Color avg = new Color(averageColor, averageColor, averageColor);

                // set the pixel at that position to the new Color object using Color.getRGB().            

                cat.setRGB(w, h, avg.getRGB());

            }

        }
        String greyPicPath = "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/greyscale"
                + fileName;
        greyPicPath = greyPicPath.trim();
        File outputfile = new File(greyPicPath);
        ImageIO.write(cat, "jpg", outputfile);
        System.out.println("Image is successfully converted to grayscale");

        String binPicPath = "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/binary"
                + fileName;
        File f2 = new File(binPicPath);
        System.out.println("1");
        ImageProcessor ip;
        ImagePlus imp = new ImagePlus(greyPicPath);
        System.out.println("2");
        ip = imp.getProcessor();
        ip.invertLut();
        ip.autoThreshold();
        System.out.println("3");
        BufferedImage bf = ip.getBufferedImage();
        System.out.println("4");
        ImageIO.write(bf, "jpg", f2);
        System.out.println("Image is successfully converted to binary image");
        if (choice == 1) {
            String Inserted1 = "insert into test (PhyAOR) values ('" + area + "')";
            System.out.println("InsertedQuery" + Inserted1);
            stmtnew.executeUpdate(Inserted1);
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            String ID = "select MAX(id) as id from test";
            System.out.println("Query" + ID);
            rs = stmt.executeQuery(ID);
            while (rs.next()) {
                id = rs.getInt("id");
            }
            String Inserted2 = "update test set fileName0=? where id=?";
            PreparedStatement ps = con.prepareStatement(Inserted2);
            ps.setString(1, fileName);
            ps.setDouble(2, id);
            int rt = ps.executeUpdate();
            choice++;
        }
        System.out.println(choice);
        if (value == 1) {

            int count = countblackpixel(binPicPath);
            calculatepixA(count, area);
            //returnVal=value+"/"+count+"/"+OnepixArea;

        } else if (value == 2) {

            int flag = countblackpixel(binPicPath);
            // calculatepixA(flag, area);
            leafarea0(flag, area);
            //returnVal=value+"/"+flag+"/"+OnepixArea+"/"+leafArea0;
            //System.out.println(returnVal);
        } else if (value == 3) {
            String Inserted3 = "update test set fileName180=? where id=?";
            PreparedStatement ps1 = con.prepareStatement(Inserted3);
            ps1.setString(1, fileName);
            ps1.setDouble(2, id);
            int rt = ps1.executeUpdate();
            int black = countblackpixel(binPicPath);
            leafarea180(area, black);
            finalarea();
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            String finalans = "select PhyAOR,onePixA,leafarea0,leafarea180,finalleafarea from test where id="
                    + id + "";
            rs = stmt.executeQuery(finalans);
            while (rs.next()) {
                returnVal = rs.getString("PhyAOR") + "/" + rs.getString("onePixA") + "/"
                        + rs.getString("leafarea0") + "/" + rs.getString("leafarea180") + "/"
                        + rs.getString("finalleafarea");
            }
            //returnVal=value+"/"+black+"/"+OnepixArea+"/"+leafArea180+"/"+Leaf_Area;
        } else if (value == 4) {
            finalarea();

        }
        imageOutFile.close();
    } catch (Exception ex) {
        Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println(ex);

    }
    return returnVal;

}

From source file:org.efaps.db.wrapper.AbstractSQLInsertUpdate.java

/**
 * Defines a new column <code>_columnName</code> with {@link Double}
 * <code>_value</code> within this SQL insert / update statement.
 *
 * @param _columnName   name of the column
 * @param _value        value of the column
 * @return this SQL statement/*  www .j ava 2s .  c o m*/
 */
@SuppressWarnings("unchecked")
public STMT column(final String _columnName, final Double _value) {
    this.columnWithValues.add(new AbstractSQLInsertUpdate.AbstractColumnWithValue<Double>(_columnName, _value) {
        @Override
        public void set(final int _index, final PreparedStatement _stmt) throws SQLException {
            if (getValue() == null) {
                _stmt.setNull(_index, Types.DECIMAL);
            } else {
                _stmt.setDouble(_index, getValue());
            }
        }
    });
    return (STMT) this;
}

From source file:com.dbsvg.models.SQLiteInternalDataDAO.java

/**
 * Inserts or updates a TableView//from w ww .  j  a v  a 2s.com
 * 
 * @param tv
 * @param conn
 * @throws SQLException
 */
public void saveTablePosition(TableView tv, Connection conn) throws SQLException {
    String insertTableViewSQL = "INSERT OR REPLACE INTO table_page_position (pageid,tableid,x_pos,y_pos) VALUES (?,?,?,?);";
    PreparedStatement ps = conn.prepareStatement(insertTableViewSQL);
    ps.setString(1, tv.getPage().getId().toString());
    ps.setString(2, tv.getTable().getId().toString());
    ps.setDouble(3, tv.getX());
    ps.setDouble(4, tv.getY());
    ps.executeUpdate();
    ps.close();

    LOG.info("Saved TableView {}", tv);
}

From source file:com.amazonbird.announce.ProductMgrImpl.java

public void updateProduct(Product product) {
    Connection connection = null;
    PreparedStatement ps = null;

    try {//from   ww w  .j  a v  a 2  s.  c  o  m
        connection = dbMgr.getConnection();
        ps = connection.prepareStatement(UPDATE_PRODUCT);
        ps.setString(1, product.getName());
        ps.setDouble(2, product.getPrice());
        ps.setString(3, product.getDestination());
        ps.setString(4, product.getAlternativeDestionation());
        ps.setString(5, product.getLocale());
        ps.setLong(6, product.getAnnouncerId());
        ps.setLong(7, product.getId());
        ps.executeUpdate();
        logger.debug(DBConstants.QUERY_EXECUTION_SUCC + ps.toString());
    } catch (SQLException ex) {
        logger.error(DBConstants.QUERY_EXECUTION_FAIL + ps.toString(), ex);
    } finally {
        dbMgr.closeResources(connection, ps, null);
    }
}

From source file:org.xenei.bloomgraph.bloom.sql.MySQLCommands.java

@Override
public int tripleCount(final Connection connection, final int pageId, final TripleBloomFilter filter)
        throws SQLException, IOException {
    final String sql = String.format(
            "SELECT count(*) FROM Page_%%s page WHERE hamming>=? AND log>=? AND bloommatch( ?, page.bloom)",
            pageId);/*from ww w .ja  v  a2s.  c  o  m*/
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        stmt = connection.prepareStatement(sql);
        stmt.setInt(1, filter.getHammingWeight());
        stmt.setDouble(2, filter.getApproximateLog(APPROX_LOG_DEPTH));
        stmt.setBlob(3, DBIO.asInputStream(filter.getByteBuffer()));
        rs = stmt.executeQuery();
        if (rs.next()) {
            return rs.getInt(1);
        } else {
            throw new IOException("No result returned from count call");
        }
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(stmt);
    }
}

From source file:com.jernejerin.traffic.helper.TripOperations.java

/**
 * Insert a trip into database.//from  w w  w .j  ava 2  s .  co m
 *
 * @param trip trip to insert.
 * @param table table into which we need to insert trip
 */
public static void insertTrip(Trip trip, String table) {
    //        LOGGER.log(Level.INFO, "Started inserting trip into DB for trip = " +
    //                trip.toString() + " from thread = " + Thread.currentThread());
    PreparedStatement insertTrip = null;
    Connection conn = null;
    try {
        // first we need to get connection from connection pool
        conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:taxi");

        // setting up prepared statement
        insertTrip = conn.prepareStatement("insert into " + table
                + " (eventId, medallion, hack_license, pickup_datetime, "
                + "dropoff_datetime, trip_time, trip_distance, pickup_longitude, pickup_latitude, dropoff_longitude, "
                + "dropoff_latitude, payment_type, fare_amount, surcharge, mta_tax, tip_amount, tolls_amount, "
                + "total_amount, timestampReceived) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

        insertTrip.setInt(1, trip.getId());
        insertTrip.setString(2, trip.getMedallion());
        insertTrip.setString(3, trip.getHackLicense());
        insertTrip.setTimestamp(4,
                new Timestamp(trip.getPickupDatetime().toEpochSecond(ZoneOffset.UTC) * 1000));
        insertTrip.setTimestamp(5,
                new Timestamp(trip.getDropOffDatetime().toEpochSecond(ZoneOffset.UTC) * 1000));
        insertTrip.setInt(6, trip.getTripTime());
        insertTrip.setDouble(7, trip.getTripDistance());
        insertTrip.setDouble(8, trip.getPickupLongitude());
        insertTrip.setDouble(9, trip.getPickupLatitude());
        insertTrip.setDouble(10, trip.getDropOffLongitude());
        insertTrip.setDouble(11, trip.getDropOffLatitude());
        insertTrip.setString(12, trip.getPaymentType() != null ? trip.getPaymentType().name() : null);
        insertTrip.setDouble(13, trip.getFareAmount());
        insertTrip.setDouble(14, trip.getSurcharge());
        insertTrip.setDouble(15, trip.getMtaTax());
        insertTrip.setDouble(16, trip.getTipAmount());
        insertTrip.setDouble(17, trip.getTollsAmount());
        insertTrip.setDouble(18, trip.getTotalAmount());
        insertTrip.setLong(19, trip.getTimestampReceived());

        insertTrip.execute();
    } catch (SQLException e) {
        LOGGER.log(Level.SEVERE, "Problem when inserting ticket into DB for ticket = " + trip
                + " from thread = " + Thread.currentThread());
    } finally {
        try {
            if (insertTrip != null)
                insertTrip.close();
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Problem with closing prepared statement for ticket = " + trip
                    + " from thread = " + Thread.currentThread());
        }
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Problem with closing connection from thread = " + Thread.currentThread());
        }
        //            LOGGER.log(Level.INFO, "Finished inserting ticket into DB for for ticket = " +
        //                    trip + " from thread = " + Thread.currentThread());
    }
}

From source file:com.imagelake.control.PaymentPreferenceDAOImp.java

@Override
public boolean AddPaymentPreference(PaymentPreferences pp) {
    boolean ok = false;
    try {//from  w w  w . ja va  2 s. com
        String sql = "INSERT INTO payment_preferences(user_id,date,conf_date,acc_type,adm_id,amount,state,email) VALUES(?,?,?,?,?,?,?,?)";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
        ps.setInt(1, pp.getUser_id());
        ps.setString(2, pp.getDate());
        ps.setString(3, pp.getConf_date());
        ps.setInt(4, pp.getAcc_type());
        ps.setInt(5, pp.getAdm_id());
        ps.setDouble(6, pp.getAmount());
        ps.setInt(7, pp.getState());
        ps.setString(8, pp.getEmail());

        int i = ps.executeUpdate();
        if (i > 0) {
            ok = true;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return ok;
}

From source file:org.georchestra.mapfishapp.addons.notes.NoteBackend.java

/**
 * Store note in database configured in this backend.
 * @param note note to store in this backend
 *///  ww w  . ja  v a2s .c  o m
public void store(Note note) throws SQLException {

    Connection connection = null;
    PreparedStatement st = null;
    // try {
    connection = this.basicDataSource.getConnection();
    st = connection.prepareStatement("INSERT INTO " + this.table
            + "(followup, email, comment, map_context, login, the_geom) VALUES (?,?,?,?,?,ST_SetSRID(ST_MakePoint(?,?),?))");
    st.setBoolean(1, note.getFollowUp());
    st.setString(2, note.getEmail());
    st.setString(3, note.getComment());
    st.setString(4, note.getMapContext());
    st.setString(5, note.getLogin());
    st.setDouble(6, note.getLongitude());
    st.setDouble(7, note.getLatitude());
    st.setInt(8, this.srid);
    st.executeUpdate();
    //        }
    //        catch (SQLException e) {
    //            throw new RuntimeException(e);
    //        } finally {
    //            if (st != null) try { st.close(); } catch (SQLException e) {LOG.error(e);}
    //            if (connection != null) try { connection.close(); } catch (SQLException e) {LOG.error(e);}
    //        }
}

From source file:gov.nih.nci.ncicb.cadsr.bulkloader.util.BulkLoaderUnclassifier.java

private void runDeleteQry(String qry, final Object[] args) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update(qry, new PreparedStatementSetter() {

        @Override/* w w w  . j  av a 2 s. co m*/
        public void setValues(PreparedStatement ps) throws SQLException {
            for (int i = 0; i < args.length; i++) {
                Object o = args[i];
                if (o instanceof String) {
                    ps.setString(i + 1, (String) o);
                } else if (o instanceof Integer) {
                    ps.setInt(i + 1, (Integer) o);
                } else if (o instanceof Double) {
                    ps.setDouble(i + 1, (Double) o);
                }
            }
        }

    });
}