List of usage examples for java.sql CallableStatement getInt
int getInt(String parameterName) throws SQLException;
INTEGER
parameter as an int
in the Java programming language. From source file:sd_conexion_bd.Servicios.java
/** * procedimiento que permite al usuario crear un nuevo grupo */// w w w . ja v a 2 s. c o m public boolean registrar_grupo(String nombre, String descripcion, JList integrantes_lista, int creadorID) throws ClassNotFoundException { //registrar grupo int id_grupo = 0; String nomb_apellido; try { this.conectar("localhost:3306", "mensajeria", "mensajeria", "1234"); //this.conectar("192.168.43.21:3306", "mensajeria","mensajeria","1234"); String sql = "{call registrar_grupo(?, ?, ?, ?)}"; CallableStatement cstmt = conexion.prepareCall(sql); cstmt.setString(1, nombre); cstmt.setString(2, descripcion); cstmt.setInt(3, creadorID); // Because parameter is OUT so register it cstmt.registerOutParameter(4, java.sql.Types.INTEGER); cstmt.execute();//retorna el id del grupo por el parametro tipo out del procedure id_grupo = cstmt.getInt(4); if (id_grupo != 0) { //agregar uno a uno los integrantes con el id respectivo (while) for (int i = 0; i < integrantes_lista.getModel().getSize(); i++) { nomb_apellido = (String) integrantes_lista.getModel().getElementAt(i); this.consulta = this.conexion.prepareStatement("call registrar_integrante(\"" + nomb_apellido + "\",\"" + creadorID + "\",\"" + id_grupo + "\");"); this.consulta.executeUpdate();//ingresa uno a uno los integrantes } } else { JOptionPane.showMessageDialog(null, "No se pudo registrar el grupo"); } //no se ingreso el grupo this.conexion.close(); return true; } catch (SQLException ex) { Logger.getLogger(Servicios.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, "No se pudo conectar correctamente a la base de datos"); } return false; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Add a metric alarm//from ww w . ja v a2 s. c o m * * @param alarmName * @param alarmDescription * @param comparisonOperator * @param metricNamespace * @param metricName * @param satistic * @param threshold * @param unit * @return lastId */ @Override public Integer addMetricAlarm(String alarmName, String alarmDescription, AlarmComparisonOperator comparisonOperator, String metricNamespace, String metricName, MetricStatistic statistic, Double threshold, MetricUnit unit) { Integer lastId = 0; Connection conn = null; CallableStatement stmt = null; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); // create new alarm stmt = conn.prepareCall("uspMetricAlarm_Insert(?,?,?,?,?,?,?,?,?,?,?,?)"); stmt.setInt(1, comparisonOperator.getValue()); stmt.setInt(2, statistic.getValue()); stmt.setInt(3, unit.getValue()); stmt.setString(4, alarmName); stmt.setString(5, alarmDescription); stmt.setString(6, metricNamespace); stmt.setString(7, metricName); stmt.setDouble(8, threshold); stmt.setString(9, null); stmt.setString(10, null); stmt.setInt(11, AlarmState.OK.getValue()); stmt.registerOutParameter(12, Types.INTEGER); stmt.execute(); lastId = stmt.getInt(12); } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return lastId; }
From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java
/** * Add metric sla//from www . j a v a 2 s . co m * * @param metricAlarmId * @param slaName * @param slaDescription * @param percentage * @param lastId */ @Override public Integer addMetricSla(Integer metricAlarmId, String slaName, String slaDescription, Double percentage) { Connection conn = null; CallableStatement stmt = null; Integer lastId = 0; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); conn = DriverManager.getConnection(this.host + ";user=" + this.username + ";password=" + this.password); // create new sla stmt = conn.prepareCall("uspMetricSla_Insert(?,?,?,?,?)"); stmt.setInt(1, metricAlarmId); stmt.setString(2, slaName); stmt.setString(3, slaDescription); stmt.setDouble(4, percentage); stmt.registerOutParameter(5, Types.INTEGER); stmt.execute(); lastId = stmt.getInt(5); } catch (SQLException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { this.loggingManager.LogError("Error : " + e.getClass().getName(), e.getMessage()); e.printStackTrace(); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } return lastId; }
From source file:tds.dll.mysql.StudentDLL.java
public void _CanOpenTestOpportunity_SP_Mysql(SQLConnection connection, String clientname, Long testee, String testkey, UUID sessionId, Integer maxOpportunities, _Ref<Boolean> newRef, _Ref<Integer> numberRef, _Ref<String> reasonRef) throws ReturnStatusException { try {// ww w. j av a2 s .c o m String sessionIdStr = sessionId.toString().replaceAll("-", ""); sessionIdStr = String.format("0x%s", sessionIdStr); final String SQL_QUERY = "{call _canopentestopportunity(?,?,?," + sessionIdStr + ",?,?,?,?,?)}"; CallableStatement callableStatement = connection.prepareCall(SQL_QUERY); callableStatement.setString(1, clientname); callableStatement.setLong(2, testee); callableStatement.setString(3, testkey); callableStatement.setInt(4, maxOpportunities); callableStatement.registerOutParameter(5, java.sql.Types.BOOLEAN); callableStatement.registerOutParameter(6, java.sql.Types.INTEGER); callableStatement.registerOutParameter(7, java.sql.Types.VARCHAR); callableStatement.setInt(8, 0); callableStatement.executeUpdate(); newRef.set(callableStatement.getBoolean(5)); numberRef.set(callableStatement.getInt(6)); reasonRef.set(callableStatement.getString(7)); } catch (SQLException e) { throw new ReturnStatusException(e); } }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Takes a callable statement and retrieves the out parameters, displaying * them in the message area of the GUI./*from w ww . ja va 2s .com*/ * * @param stmt * CallableStatement just executed * @param params * List of parameters used in the callable statement * @return List */ private List<Object> getOutParams(CallableStatement stmt, List<StatementParameter> params) { List<Object> values; int paramIndex; StatementParameter param; paramIndex = 0; values = new ArrayList<Object>(); try { for (paramIndex = 0; paramIndex < params.size(); ++paramIndex) { param = (StatementParameter) params.get(paramIndex); if (param.getType() == StatementParameter.OUT) { messageOut(Resources.getString("msgOutParam") + " ", STYLE_SUBTLE, false); switch (param.getDataType()) { case java.sql.Types.VARCHAR: messageOut(Resources.getString("msgParamString", paramIndex + "") + " ", STYLE_SUBTLE, false); messageOut(stmt.getString(paramIndex + 1), STYLE_BOLD, true); values.add(stmt.getString(paramIndex + 1)); break; case java.sql.Types.INTEGER: messageOut(Resources.getString("msgParamInteger", paramIndex + "") + " ", STYLE_SUBTLE, false); messageOut("" + stmt.getInt(paramIndex + 1), STYLE_BOLD, true); values.add(new Integer(stmt.getInt(paramIndex + 1))); break; default: messageOut(Resources.getString("msgParamDefault", paramIndex + "") + " ", STYLE_SUBTLE, false); messageOut("" + stmt.getObject(paramIndex + 1), STYLE_BOLD, true); values.add(stmt.getObject(paramIndex + 1)); break; } } } } catch (Throwable any) { LOGGER.error("Failed to read output parameter at index (" + paramIndex + ")", any); messageOut(Resources.getString("errFailReadingOutParam", paramIndex + "", any.getMessage())); } return values; }