List of usage examples for java.sql PreparedStatement setString
void setString(int parameterIndex, String x) throws SQLException;
String
value. From source file:FacultyAdvisement.StudentRepository.java
public static Student readById(DataSource ds, String key) throws SQLException { String studentSQL = "SElECT * FROM STUDENT WHERE STUID = ?"; Student student = new Student(); if (ds == null) { throw new SQLException("ds is null; Can't get data source"); }/*from www . j a v a 2 s .c om*/ Connection conn = ds.getConnection(); if (conn == null) { throw new SQLException("conn is null; Can't get db connection"); } try { PreparedStatement sqlStatement = conn.prepareStatement(studentSQL); sqlStatement.setString(1, key); ResultSet result = sqlStatement.executeQuery(); while (result.next()) { student.setId(key); student.setFirstName(result.getString("firstname")); student.setLastName(result.getString("lastname")); student.setMajorCode(result.getString("majorcode")); student.setPhoneNumber(result.getString("phone")); student.setUsername(result.getString("email")); } } finally { conn.close(); } return student; }
From source file:net.codjo.dataprocess.server.treatmenthelper.TreatmentHelper.java
public static void initRepositoryUserAccess(Connection con, String userName, List<RepositoryDescriptor> repositoryDescList) throws SQLException { User user = new User(); user.setUserName(userName);/*w ww. ja v a 2 s .c o m*/ for (RepositoryDescriptor repoDescriptor : repositoryDescList) { user.addRepository(new Repository(repoDescriptor.getRepositoryName())); } String xml = new UserXStreamImpl().toXml(user); PreparedStatement pStmt = con.prepareStatement("delete from PM_DP_USER where USER_NAME = ? " + " insert into PM_DP_USER (USER_NAME, USER_PARAM) values (?, ?)"); try { pStmt.setString(1, userName); pStmt.setString(2, userName); pStmt.setString(3, xml); pStmt.executeUpdate(); LOG.info(String.format("Droits d'accs accords l'utilisateur '%s' pour tous les repositories.", userName)); } finally { pStmt.close(); } }
From source file:com.wso2telco.core.mnc.resolver.mncrange.McnRangeDbUtil.java
public static String getMncBrand(String mcc, String mnc) throws MobileNtException { Connection conn = null;/* w w w . jav a 2 s .com*/ PreparedStatement ps = null; ResultSet rs = null; String sql = "SELECT operatorname " + "FROM operators " + "WHERE mcc = ? AND mnc = ?"; String mncBrand = null; try { conn = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB); ps = conn.prepareStatement(sql); ps.setString(1, mcc); ps.setString(2, mnc); rs = ps.executeQuery(); if (rs.next()) { mncBrand = rs.getString("operatorname"); } } catch (SQLException e) { handleException("Error occured while getting Brand for for mcc: and mnc: " + mcc + ":" + mnc + " from the database", e); } catch (Exception e) { handleException("Error occured while getting Brand for for mcc: and mnc: " + mcc + ":" + mnc + " from the database", e); } finally { DbUtils.closeAllConnections(ps, conn, rs); } return mncBrand; }
From source file:ca.qc.adinfo.rouge.mail.db.MailDb.java
public static boolean setMailAsRead(DBManager dbManager, long mailId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;/*from w w w . j a v a 2 s . c o m*/ String sql = null; sql = "UPDATE rouge_mail SET `status` = ? WHERE `id` = ? "; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, "rea"); stmt.setLong(2, mailId); int ret = stmt.executeUpdate(); return (ret > 0); } catch (SQLException e) { log.error(stmt); log.error(e); return false; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:ca.qc.adinfo.rouge.mail.db.MailDb.java
public static boolean deleteMail(DBManager dbManager, long mailId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;//w ww . j ava 2 s . co m String sql = null; sql = "UPDATE rouge_mail SET `status` = ? WHERE `id` = ? "; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, "del"); stmt.setLong(2, mailId); int ret = stmt.executeUpdate(); return (ret > 0); } catch (SQLException e) { log.error(stmt); log.error(e); return false; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:ch.newscron.referral.ReferralManager.java
public static int numberOfRegisteredUsers(String shortURL) { Connection connection = null; PreparedStatement query = null; ResultSet rs = null;/*from w w w .j a va 2s .c om*/ try { connection = connect(); query = connection.prepareStatement( "SELECT COUNT(*) as total FROM User, ShortURL WHERE User.campaignId = ShortURL.id AND ShortURL.shortUrl = ?"); query.setString(1, shortURL); rs = query.executeQuery(); rs.next(); int totalNumbUsers = rs.getInt("total"); return totalNumbUsers; } catch (Exception ex) { Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex); } finally { disconnect(connection, query, rs); } return -1; }
From source file:com.wso2telco.util.DbUtil.java
public static void insertPinAttempt(String msisdn, int attempts, String sessionId) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "insert into multiplepasswords(username, attempts, ussdsessionid) values (?,?,?);"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setString(1, msisdn); ps.setInt(2, attempts);/*from w w w.j a va2s. c o m*/ ps.setString(3, sessionId); ps.execute(); if (connection != null) { connection.close(); } }
From source file:com.wso2telco.util.DbUtil.java
public static void updatePin(int pin, String sessionId) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "update multiplepasswords set pin=? where ussdsessionid = ?;"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setInt(1, pin);/*from w ww. jav a 2 s . c o m*/ ps.setString(2, sessionId); ps.execute(); if (connection != null) { connection.close(); } }
From source file:com.keybox.manage.db.SystemStatusDB.java
/** * inserts into the status table to keep track of key placement status * * @param con DB connection object * @param hostSystem systems for authorized_keys replacement * @param userId user id/*from w w w. j a v a 2 s . c o m*/ */ private static void insertSystemStatus(Connection con, HostSystem hostSystem, Long userId) { try { PreparedStatement stmt = con .prepareStatement("insert into status (id, status_cd, user_id) values (?,?,?)"); stmt.setLong(1, hostSystem.getId()); stmt.setString(2, hostSystem.getStatusCd()); stmt.setLong(3, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:FacultyAdvisement.StudentRepository.java
public static String getPicture(DataSource ds, String key) throws SQLException { Blob image = null;//from w w w . j a va 2s.c o m Connection conn = ds.getConnection(); if (conn == null) { throw new SQLException("conn is null; Can't get db connection"); } try { PreparedStatement ps = conn.prepareStatement("SELECT * FROM USERTABLE WHERE USERNAME = ?"); ps.setString(1, key); ResultSet result = ps.executeQuery(); while (result.next()) { image = result.getBlob("IMAGE"); } } finally { conn.close(); } if (image != null) { return "ImageServlet?username=" + key; } else { return "/resources/default-image.png"; } }