List of usage examples for java.sql PreparedStatement setDouble
void setDouble(int parameterIndex, double x) throws SQLException;
double
value. From source file:org.sleuthkit.autopsy.casemodule.SingleUserCaseConverter.java
/** * Place a NULL inside a prepared statement if needed, otherwise, place the * double that was in the ResultSet./*from w ww .ja va2s .c o m*/ * * @param pst the prepared statement * @param rs the ResultSet to work with * @param rsIndex index for the result set * @param psIndex index for the prepared statement * * @throws SQLException */ private static void populateNullableNumeric(PreparedStatement pst, ResultSet rs, int rsIndex, int psIndex) throws SQLException { double nullableNumeric = rs.getDouble(rsIndex); if (rs.wasNull()) { pst.setNull(psIndex, java.sql.Types.NULL); } else { pst.setDouble(psIndex, nullableNumeric); } }
From source file:com.imagelake.control.PaymentPreferenceDAOImp.java
public boolean updateMinEarning(double earn, int id) { boolean b = false; try {/*from ww w. jav a 2s . c o m*/ String sql = "UPDATE min_earning SET minearning=? WHERE id=?"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setDouble(1, earn); ps.setInt(2, id); int i = ps.executeUpdate(); if (i > 0) { b = true; } } catch (Exception e) { e.printStackTrace(); } return b; }
From source file:pack1.test.java
public void calculatepixA(double count, double AOR) { try {/* w w w . j a v a2 s . c om*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("connected"); Connection con = DriverManager.getConnection("jdbc:odbc:test"); System.out.println(" driver loaded in connection.jsp"); OnepixArea = AOR / count; OnepixArea = Math.round(OnepixArea * 10000.0) / 10000.0; System.out.println(OnepixArea); String Inserted3 = "update test set onePixA=? where id=?"; PreparedStatement ps1 = con.prepareStatement(Inserted3); ps1.setDouble(1, OnepixArea); ps1.setInt(2, id); int rt1 = ps1.executeUpdate(); System.out.println("OnePixA updated" + OnepixArea); } catch (Exception ex) { Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex); System.out.println(ex); } }
From source file:pack1.test.java
public void leafarea0(double flag, double area) { try {/* w w w.j av a 2 s. c o m*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:test"); Statement stmt = con.createStatement(); ResultSet rs = null; String OnePixA = "select onePixA from test where id=" + id + ""; rs = stmt.executeQuery(OnePixA); double opa = 0; while (rs.next()) { opa = rs.getDouble("onePixA"); opa = Math.round(opa * 10000.0) / 10000.0; } leafArea0 = flag * opa; leafArea0 = Math.round(leafArea0 * 10000.0) / 10000.0; String str = "update test set leafArea0=? where id=?"; PreparedStatement ps = con.prepareStatement(str); ps.setDouble(1, leafArea0); ps.setInt(2, id); int rt = ps.executeUpdate(); System.out.println("Leaf area0 is uploaded to database" + leafArea0); } catch (Exception ex) { Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex); System.out.println(ex); } }
From source file:pack1.test.java
public void leafarea180(double AOR, double flag) { try {/*from w w w . ja v a 2 s .c o m*/ double onePixArea = 0; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("connected"); Connection con = DriverManager.getConnection("jdbc:odbc:test"); System.out.println(" driver loaded in connection.jsp"); Statement stmt = con.createStatement(); ResultSet rs = null; String OnePixA = "select onePixA from test where id='" + id + "'"; rs = stmt.executeQuery(OnePixA); while (rs.next()) { onePixArea = rs.getDouble("onePixA"); onePixArea = Math.round(onePixArea * 10000.0) / 10000.0; } leafArea180 = flag * onePixArea; leafArea180 = Math.round(leafArea180 * 10000.0) / 10000.0; System.out.println(leafArea180); String str = "update test set leafArea180=? where id=?"; PreparedStatement ps = con.prepareStatement(str); ps.setDouble(1, leafArea180); ps.setInt(2, id); int rt = ps.executeUpdate(); System.out.println("Leaf area180 is uploaded to database" + leafArea180); } catch (Exception ex) { Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex); System.out.println(ex); } }
From source file:pack1.test.java
private void finalarea() { try {//from w ww . j a va 2 s .co m Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:test"); Statement stmt = con.createStatement(); ResultSet rs = null; String LA0 = "select leafarea0 from test where id=" + id + ""; rs = stmt.executeQuery(LA0); double la0 = 0; while (rs.next()) { la0 = rs.getDouble("leafarea0"); } String LA180 = "select leafarea180 from test where id=" + id + ""; rs = stmt.executeQuery(LA180); double la180 = 0; while (rs.next()) { la180 = rs.getDouble("leafarea180"); } Leaf_Area = 30.57 + 1.21 * la0 - 0.6 * la180; System.out.println(Leaf_Area); String str = "update test set finalleafarea=? where id=?"; PreparedStatement ps = con.prepareStatement(str); ps.setDouble(1, Leaf_Area); ps.setInt(2, id); int rt = ps.executeUpdate(); System.out.println("final area is uploaded to database" + Leaf_Area); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } catch (Exception ex) { Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex); System.out.println(ex); } }
From source file:com.sai.storm.DataSaver.java
@Override public void execute(Tuple input, BasicOutputCollector collector) { try {/* ww w.j a va2s . co m*/ String city = input.getStringByField("city"); org.json.JSONObject jsonObject = new org.json.JSONObject(city); LOG.info("DataSaver>>>>>>>>>>>>>>>>>>>>>." + jsonObject.getString("name") + ">" + jsonObject.getJSONObject("main").getString("temp")); PreparedStatement preparedStatement = conn .prepareStatement("insert into weather_data values(default,?,?,?,?,?,?,?)"); preparedStatement.setString(1, jsonObject.getString("name")); preparedStatement.setString(2, jsonObject.getString("dt")); preparedStatement.setString(3, jsonObject.getJSONObject("main").getString("temp")); preparedStatement.setDouble(4, jsonObject.getJSONObject("main").getDouble("temp_min")); preparedStatement.setDouble(5, jsonObject.getJSONObject("main").getDouble("temp_max")); preparedStatement.setDouble(6, jsonObject.getJSONObject("main").getDouble("humidity")); preparedStatement.setDouble(7, jsonObject.getJSONObject("main").getDouble("pressure")); preparedStatement.executeUpdate(); } catch (JSONException ex) { Logger.getLogger(DataSaver.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(DataSaver.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Project.DB_Users.java
public void insertProduct(String category, String keyword, String images, double cost, String user) { try {//from w w w . j av a 2 s. c om Connection con = getConnection(); String query = "INSERT INTO products(category,keyword,images,cost,user) VALUES(?,?,?,?,?)"; PreparedStatement stmt = con.prepareStatement(query); stmt.setString(1, category); stmt.setString(2, keyword); stmt.setString(3, images); stmt.setDouble(4, cost); stmt.setString(5, user); stmt.executeUpdate(); } catch (SQLException e) { System.out.println("Error"); } }
From source file:nl.tudelft.stocktrader.derby.DerbyOrderDAO.java
public void updateOrder(Order order) throws DAOException { PreparedStatement updateHoldingStat = null; try {/*from www . j a v a2s. c o m*/ updateHoldingStat = sqlConnection.prepareStatement(SQL_UPDATE_ORDER); updateHoldingStat.setDouble(1, order.getQuantity()); updateHoldingStat.setInt(2, order.getOrderID()); updateHoldingStat.executeUpdate(); } catch (SQLException e) { throw new DAOException("An Exception is thrown during updating a holding entry", e); } finally { if (updateHoldingStat != null) { try { updateHoldingStat.close(); } catch (Exception e) { logger.debug("", e); } } } }