Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- PreparedStatement stm;
- stm = connex.getConexao().prepareStatement("INSERT INTO onibus "
- + "(ano, chassi, placa, numeroOnibus, tipoVeiculo) "
- + "VALUES (?,?,?,?,?);");
- stm.setInt(1, onibus.getAno());
- stm.setString(2, onibus.getChassi());
- stm.setString(3, onibus.getPlaca());
- stm.setInt(4, onibus.getNumeroOnibus());
- stm.setString(5, onibus.getTipoVeiculo());
- stm.execute();
- JOptionPane.showMessageDialog(null, "Onibus Inserido Com Sucesso!");
- } catch (HeadlessException | SQLException e) {
- JOptionPane.showMessageDialog(null, "Erro ao inserir Onibus!nERRO");
- e.printStackTrace();
- } finally {
- connex.desconecta();
- }
- }
- public Statement stm;
- public ResultSet rst;
- private final String driver = "org.postgresql.Driver";
- private final String url = "jdbc:postgresql://localhost:5432/CONI-VP";
- private final String usuario = "postgres";
- private final String senha = "root";
- Connection conexao = null;
- public Conexao(){
- try {
- Class.forName(driver);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public Conexao(Statement stm, ResultSet rst) {
- this.stm = stm;
- this.rst = rst;
- }
- public Connection getConexao(){
- if(conexao == null){
- try {
- conexao = DriverManager.getConnection(url, usuario, senha);
- conexao.setAutoCommit(false);
- } catch (SQLException e) {
- }
- }
- return conexao;
- }
- public void desconecta(){
- try {
- conexao.close();
- } catch (SQLException e) {
- }
- conexao = null;
- }
- }
- o.setAno(Integer.parseInt(jFormatted_ano.getText()));
- o.setNumeroOnibus(Integer.parseInt(jFormatted_numOnibus.getText()));
- o.setChassi(jTextField_tipo.getText());
- o.setPlaca(jTextField_placa.getText());
- o.setTipoVeiculo(jTextField_tipo.getText());
- }
- o.getCodOnibus();
- o.setAno(Integer.parseInt(jFormatted_ano.getText()));
- o.setNumeroOnibus(Integer.parseInt(jFormatted_numOnibus.getText()));
- o.setChassi(jTextField_chassi1.getText());
- o.setPlaca(jTextField_placa.getText());
- o.setTipoVeiculo(jTextField_tipo.getText());;
- dao.inserirOnibus(o);
- jFormatted_ano.setText("");
- jFormatted_numOnibus.setText("");
- jTextField_tipo.setText("");
- jTextField_placa.setText("");
- jTextField_chassi1.setText("");
Add Comment
Please, Sign In to add comment