Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Inserção no banco de dados
- Conexao con = Conexao.getInstance();
- String sql = "SELECT * FROM TABELA WHERE USUARIO = '10'";
- PreparedStatement STATEMENT = con.getConnection().prepareStatement(sql);
- ResultSet rs = STATEMENT.executeQuery();
- if(rs.isBeforeFirst()){ //Verifica se existem registros no ResultSet
- rs.next();
- String sql = "INSERT INTO TABELA(CAMPO, CAMPO) VALUES(?,?)";
- PreparedStatement ps = con.getConnection().prepareStatement(sql);
- ps.setString(1, rs.getString("CAMPO"));
- ps.setString(2, rs.getInt("CAMPO"));
- int i = ps.executeUpdate();
- if(i == 1) //Verifica se o registro foi inserido
- {
- System.out.println("Inserido com sucesso!");
- }else{
- System.out.println("Problemas na inserção dos dados!");
- }
- }else {
- System.out.println("Problemas na inserção dos dados!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement