List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:Main.java
public static byte[] getBLOB(int id, Connection conn) throws Exception { ResultSet rs = null;//from w ww.j ava 2 s . co m PreparedStatement pstmt = null; String query = "SELECT photo FROM MyPictures WHERE id = ?"; try { pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); rs = pstmt.executeQuery(); rs.next(); Blob blob = rs.getBlob(3); // materialize BLOB onto client return blob.getBytes(1, (int) blob.length()); } finally { rs.close(); pstmt.close(); conn.close(); } }
From source file:Main.java
public static byte[] getBLOB(int id, Connection conn) throws Exception { ResultSet rs = null;/*from w w w . j a va 2 s .c o m*/ PreparedStatement pstmt = null; String query = "SELECT photo FROM MyPictures WHERE id = ?"; try { pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); rs = pstmt.executeQuery(); rs.next(); Blob blob = rs.getBlob("photo"); // materialize BLOB onto client return blob.getBytes(1, (int) blob.length()); } finally { rs.close(); pstmt.close(); conn.close(); } }
From source file:com.xpfriend.fixture.runner.example.ExampleJob.java
/** * ??/* www . j a va 2s . c o m*/ * @param id ?ID * @param name?NAME * @param connection ? */ private static void updateDatabase(int id, String name, Connection connection) throws SQLException { PreparedStatement statement = connection.prepareStatement(SQL); try { statement.setString(1, name); statement.setInt(2, id); statement.executeUpdate(); } finally { statement.close(); } }
From source file:Main.java
public static String getCLOB(int id) throws Exception { Connection conn = null;/*from w ww . j a v a 2 s.c o m*/ ResultSet rs = null; PreparedStatement pstmt = null; String query = "SELECT clobData FROM tableName WHERE id = ?"; try { conn = getConnection(); pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); rs = pstmt.executeQuery(); rs.next(); Clob clob = rs.getClob(1); // materialize CLOB onto client String wholeClob = clob.getSubString(1, (int) clob.length()); return wholeClob; } finally { rs.close(); pstmt.close(); conn.close(); } }
From source file:com.data2semantics.yasgui.server.db.ConnectionFactory.java
private static void setDeltaApplied(Connection connect, int deltaId) throws SQLException { String sql = "INSERT INTO Deltas (Id) VALUES(?)"; PreparedStatement statement = connect.prepareStatement(sql); statement.setInt(1, deltaId); statement.executeUpdate();//from w ww .jav a2s . com }
From source file:com.sapienter.jbilling.tools.ConvertToBinHexa.java
private static void updateUserRow(int id, String password) throws SQLException { PreparedStatement stmt = connection.prepareStatement("UPDATE base_user set password = ? where ID = ?"); stmt.setString(1, password);//from ww w.j ava 2 s . c om stmt.setInt(2, id); stmt.executeUpdate(); }
From source file:Main.java
public static void execute_crop_stmt(PreparedStatement pstmt, int[] indexes, HashSet<Integer> set) throws SQLException { int cnt = 0;/*from ww w.j av a2 s . c o m*/ for (int i = 0; i < indexes.length; i++) { if (!set.contains(indexes[i])) { pstmt.setInt(1, indexes[i]); pstmt.addBatch(); cnt++; if (cnt > 5000) { pstmt.executeBatch(); cnt = 0; } } } if (cnt > 0) pstmt.executeBatch(); }
From source file:com.example.mydtapp.JdbcInputAppTest.java
public static void insertEventsInTable(int numEvents, int offset) { try {/*from w ww . j a va 2s .c om*/ Connection con = DriverManager.getConnection(URL); String insert = "insert into " + TABLE_NAME + " values (?,?,?)"; PreparedStatement stmt = con.prepareStatement(insert); for (int i = 0; i < numEvents; i++, offset++) { stmt.setInt(1, offset); stmt.setString(2, "Account_Holder-" + offset); stmt.setInt(3, (offset * 1000)); stmt.executeUpdate(); } } catch (SQLException e) { throw new RuntimeException(e); } }
From source file:libepg.util.db.AboutDB.java
/** * ?DB?????// w w w . j a va2 s .c o m * @param src * @param conn DB?? * @throws java.sql.SQLException * @see libepg.util.db.AboutDB#CRATE_TABLE * @see java.sql.Connection#createStatement() */ public static synchronized void convertToTable(List<TsPacket> src, Connection conn) throws SQLException { Statement stmt = conn.createStatement(); //? stmt.executeUpdate(AboutDB.CRATE_TABLE); //?PID?????? for (TsPacket tsp : src) { PreparedStatement insertStatement = conn.prepareStatement(INSERT_SQL); insertStatement.setInt(1, tsp.getPid()); insertStatement.setInt(2, tsp.getContinuity_counter()); insertStatement.setInt(3, 0); insertStatement.setBytes(4, tsp.getData()); insertStatement.executeUpdate(); } }
From source file:de.thejeterlp.bukkit.login.SQLAccount.java
protected static Account convert(UUID uuid) throws SQLException { checkReflection();//from w ww . ja v a 2 s.com Validate.notNull(uuid, "uuid cannot be null!"); PreparedStatement st = Login.getInstance().getDB() .getPreparedStatement("SELECT * FROM `" + Statics.USER_TABLE + "` WHERE `uuid` = ? LIMIT 1;"); st.setString(1, uuid.toString()); ResultSet rs = st.executeQuery(); while (rs.next()) { int id = rs.getInt("id"); Login.getInstance().getDB().closeResultSet(rs); Login.getInstance().getDB().closeStatement(st); PreparedStatement sta = Login.getInstance().getDB().getPreparedStatement( "SELECT * FROM `" + Statics.PASSWORD_TABLE + "` WHERE `userID` = ? LIMIT 1;"); sta.setInt(1, id); ResultSet rset = sta.executeQuery(); while (rset.next()) { String hash = rset.getString("password"); Login.getInstance().getDB().closeResultSet(rset); Login.getInstance().getDB().closeStatement(sta); return new Account(id, uuid, hash); } } return null; }