List of usage examples for java.sql Types INTEGER
int INTEGER
To view the source code for java.sql Types INTEGER.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER
.
From source file:Main.java
public static void main(String[] argv) throws Exception { Connection conn = null;//from ww w . ja v a 2 s . c o m String query = "begin proc(?,?,?); end;"; CallableStatement cs = conn.prepareCall(query); cs.setString(1, "string parameter"); cs.setInt(2, 1); cs.registerOutParameter(2, Types.INTEGER); cs.registerOutParameter(3, Types.INTEGER); cs.execute(); int parm2 = cs.getInt(2); // get the result from OUTPUT #2 int parm3 = cs.getInt(3); // get the result from OUTPUT #3 }
From source file:com.l2jfree.loginserver.tools.L2AccountManager.java
/** * Launches the interactive account manager. * // www . j a va 2s . co m * @param args ignored */ public static void main(String[] args) { // LOW rework this crap Util.printSection("Account Management"); _log.info("Please choose:"); //_log.info("list - list registered accounts"); _log.info("reg - register a new account"); _log.info("rem - remove a registered account"); _log.info("prom - promote a registered account"); _log.info("dem - demote a registered account"); _log.info("ban - ban a registered account"); _log.info("unban - unban a registered account"); _log.info("quit - exit this application"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); L2AccountManager acm = new L2AccountManager(); String line; try { while ((line = br.readLine()) != null) { line = line.trim(); Connection con = null; switch (acm.getState()) { case USER_NAME: line = line.toLowerCase(); try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("SELECT superuser FROM account WHERE username LIKE ?"); ps.setString(1, line); ResultSet rs = ps.executeQuery(); if (!rs.next()) { acm.setUser(line); _log.info("Desired password:"); acm.setState(ManagerState.PASSWORD); } else { _log.info("User name already in use."); acm.setState(ManagerState.INITIAL_CHOICE); } rs.close(); ps.close(); } catch (SQLException e) { _log.error("Could not access database!", e); acm.setState(ManagerState.INITIAL_CHOICE); } finally { L2Database.close(con); } break; case PASSWORD: try { MessageDigest sha = MessageDigest.getInstance("SHA"); byte[] pass = sha.digest(line.getBytes("US-ASCII")); acm.setPass(HexUtil.bytesToHexString(pass)); } catch (NoSuchAlgorithmException e) { _log.fatal("SHA1 is not available!", e); Shutdown.exit(TerminationStatus.ENVIRONMENT_MISSING_COMPONENT_OR_SERVICE); } catch (UnsupportedEncodingException e) { _log.fatal("ASCII is not available!", e); Shutdown.exit(TerminationStatus.ENVIRONMENT_MISSING_COMPONENT_OR_SERVICE); } _log.info("Super user: [y/n]"); acm.setState(ManagerState.SUPERUSER); break; case SUPERUSER: try { if (line.length() != 1) throw new IllegalArgumentException("One char required."); else if (line.charAt(0) == 'y') acm.setSuper(true); else if (line.charAt(0) == 'n') acm.setSuper(false); else throw new IllegalArgumentException("Invalid choice."); _log.info("Date of birth: [yyyy-mm-dd]"); acm.setState(ManagerState.DOB); } catch (IllegalArgumentException e) { _log.info("[y/n]?"); } break; case DOB: try { Date d = Date.valueOf(line); if (d.after(new Date(System.currentTimeMillis()))) throw new IllegalArgumentException("Future date specified."); acm.setDob(d); _log.info("Ban reason ID or nothing:"); acm.setState(ManagerState.SUSPENDED); } catch (IllegalArgumentException e) { _log.info("[yyyy-mm-dd] in the past:"); } break; case SUSPENDED: try { if (line.length() > 0) { int id = Integer.parseInt(line); acm.setBan(L2BanReason.getById(id)); } else acm.setBan(null); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement( "INSERT INTO account (username, password, superuser, birthDate, banReason) VALUES (?, ?, ?, ?, ?)"); ps.setString(1, acm.getUser()); ps.setString(2, acm.getPass()); ps.setBoolean(3, acm.isSuper()); ps.setDate(4, acm.getDob()); L2BanReason lbr = acm.getBan(); if (lbr == null) ps.setNull(5, Types.INTEGER); else ps.setInt(5, lbr.getId()); ps.executeUpdate(); _log.info("Account " + acm.getUser() + " has been registered."); ps.close(); } catch (SQLException e) { _log.error("Could not register an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); } catch (NumberFormatException e) { _log.info("Ban reason ID or nothing:"); } break; case REMOVE: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("DELETE FROM account WHERE username LIKE ?"); ps.setString(1, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been removed."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not remove an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case PROMOTE: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("UPDATE account SET superuser = ? WHERE username LIKE ?"); ps.setBoolean(1, true); ps.setString(2, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been promoted."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not promote an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case DEMOTE: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("UPDATE account SET superuser = ? WHERE username LIKE ?"); ps.setBoolean(1, false); ps.setString(2, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been demoted."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not demote an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case UNBAN: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("UPDATE account SET banReason = ? WHERE username LIKE ?"); ps.setNull(1, Types.INTEGER); ps.setString(2, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been unbanned."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not demote an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case BAN: line = line.toLowerCase(); try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("SELECT superuser FROM account WHERE username LIKE ?"); ps.setString(1, line); ResultSet rs = ps.executeQuery(); if (rs.next()) { acm.setUser(line); _log.info("Ban reason ID:"); acm.setState(ManagerState.REASON); } else { _log.info("Account does not exist."); acm.setState(ManagerState.INITIAL_CHOICE); } rs.close(); ps.close(); } catch (SQLException e) { _log.error("Could not access database!", e); acm.setState(ManagerState.INITIAL_CHOICE); } finally { L2Database.close(con); } break; case REASON: try { int ban = Integer.parseInt(line); con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("UPDATE account SET banReason = ? WHERE username LIKE ?"); ps.setInt(1, ban); ps.setString(2, acm.getUser()); ps.executeUpdate(); _log.info("Account " + acm.getUser() + " has been banned."); ps.close(); } catch (NumberFormatException e) { _log.info("Ban reason ID:"); } catch (SQLException e) { _log.error("Could not ban an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; default: line = line.toLowerCase(); if (line.equals("reg")) { _log.info("Desired user name:"); acm.setState(ManagerState.USER_NAME); } else if (line.equals("rem")) { _log.info("User name:"); acm.setState(ManagerState.REMOVE); } else if (line.equals("prom")) { _log.info("User name:"); acm.setState(ManagerState.PROMOTE); } else if (line.equals("dem")) { _log.info("User name:"); acm.setState(ManagerState.DEMOTE); } else if (line.equals("unban")) { _log.info("User name:"); acm.setState(ManagerState.UNBAN); } else if (line.equals("ban")) { _log.info("User name:"); acm.setState(ManagerState.BAN); } else if (line.equals("quit")) Shutdown.exit(TerminationStatus.MANUAL_SHUTDOWN); else _log.info("Incorrect command."); break; } } } catch (IOException e) { _log.fatal("Could not process input!", e); } finally { IOUtils.closeQuietly(br); } }
From source file:com.espertech.esperio.db.core.DBUtil.java
/** * Returns the object value for a given column and type. * @param rs result set//from w w w . ja v a 2 s. com * @param index column index * @param valueType value type * @return object value * @throws java.sql.SQLException if the column could not be read */ public static Object getValue(ResultSet rs, int index, int valueType) throws SQLException { if (valueType == Types.INTEGER) { return rs.getInt(index); } else if (valueType == Types.BIGINT) { return rs.getLong(index); } else if (valueType == Types.BLOB) { Blob blob = rs.getBlob(index); return getBlobValue(blob); } return rs.getObject(index); }
From source file:com.cloudera.sqoop.hive.HiveTypes.java
/** * Given JDBC SQL types coming from another database, what is the best * mapping to a Hive-specific type?/*from w w w .j a va2 s . c om*/ */ public static String toHiveType(int sqlType) { if (sqlType == Types.INTEGER) { return "INT"; } else if (sqlType == Types.VARCHAR) { return "STRING"; } else if (sqlType == Types.CHAR) { return "STRING"; } else if (sqlType == Types.LONGVARCHAR) { return "STRING"; } else if (sqlType == Types.NUMERIC) { // Per suggestion on hive-user, this is converted to DOUBLE for now. return "DOUBLE"; } else if (sqlType == Types.DECIMAL) { // Per suggestion on hive-user, this is converted to DOUBLE for now. return "DOUBLE"; } else if (sqlType == Types.BIT) { return "BOOLEAN"; } else if (sqlType == Types.BOOLEAN) { return "BOOLEAN"; } else if (sqlType == Types.TINYINT) { return "TINYINT"; } else if (sqlType == Types.SMALLINT) { return "INT"; } else if (sqlType == Types.BIGINT) { return "BIGINT"; } else if (sqlType == Types.REAL) { return "DOUBLE"; } else if (sqlType == Types.FLOAT) { return "DOUBLE"; } else if (sqlType == Types.DOUBLE) { return "DOUBLE"; } else if (sqlType == Types.DATE) { // unfortunate type coercion return "STRING"; } else if (sqlType == Types.TIME) { // unfortunate type coercion return "STRING"; } else if (sqlType == Types.TIMESTAMP) { // unfortunate type coercion return "STRING"; } else if (sqlType == Types.CLOB) { return "STRING"; } else { // TODO(aaron): Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, // BLOB, ARRAY, STRUCT, REF, JAVA_OBJECT. return null; } }
From source file:Main.java
public static String getCloverTypeFromJdbcType(int jdbcDataType) { switch (jdbcDataType) { case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return "date"; case Types.ARRAY: case Types.BINARY: case Types.DATALINK: case Types.BLOB: case Types.DISTINCT: case Types.JAVA_OBJECT: case Types.NULL: case Types.OTHER: case Types.REF: case Types.STRUCT: case Types.VARBINARY: case Types.LONGVARBINARY: System.out.println("Outputting cbyte for Type: " + jdbcDataType); return "cbyte"; case Types.BIT: case Types.BOOLEAN: return "boolean"; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.NUMERIC: case Types.REAL: return "numeric"; case Types.INTEGER: case Types.SMALLINT: return "integer"; case Types.BIGINT: return "long"; case Types.CHAR: case Types.VARCHAR: case Types.CLOB: case Types.LONGVARCHAR: return "string"; }//from w w w. ja v a2s. c o m System.out.println("Outputting string for unknown Type: " + jdbcDataType); return "string"; }
From source file:com.home.ln_spring.ch8.dao.jdbc.annotation.SfFirstNameById.java
public SfFirstNameById(DataSource dataSource) { super(dataSource, SQL); declareParameter(new SqlParameter(Types.INTEGER)); compile(); }
From source file:orz.neptune.prospring3.ch8.StoreFunctionQuery.java
public StoreFunctionQuery(DataSource dataSource) { super(dataSource, SQL); super.declareParameter(new SqlParameter(Types.INTEGER)); compile();//from ww w . ja v a2s .c o m }
From source file:com.mirth.connect.donkey.model.channel.MetaDataColumnType.java
public static MetaDataColumnType fromSqlType(int sqlType) { switch (sqlType) { case Types.VARCHAR: case Types.NVARCHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.CLOB: case Types.NCLOB: return STRING; case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.NUMERIC: case Types.REAL: return NUMBER; case Types.BOOLEAN: case Types.BIT: case Types.CHAR: return BOOLEAN; case Types.TIMESTAMP: case Types.TIME: case Types.DATE: return TIMESTAMP; }//from w ww . jav a2 s . c om return null; }
From source file:gov.nih.nci.cabig.caaers.tools.CodedEnumType.java
@Override protected int codeSqlType() { return Types.INTEGER; }
From source file:com.home.ln_spring.ch8.dao.jdbc.annotation.InsertContactTelDetail.java
public InsertContactTelDetail(DataSource dataSource) { super(dataSource, SQL_INSERT_CONTACT_TEL); declareParameter(new SqlParameter("contact_id", Types.INTEGER)); declareParameter(new SqlParameter("tel_type", Types.VARCHAR)); declareParameter(new SqlParameter("tel_number", Types.VARCHAR)); setBatchSize(BATCH_SIZE);// w w w .j a v a2 s . c o m }