Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package jdbc;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author FON
- */
- public class TESTJDBC1 {
- public static void main(String[] args) {
- dodajOdeljenje(555, "LABIS", "Beograd");
- }
- public static void dodajOdeljenje(int sifra, String naziv, String grad) {
- String url = "jdbc:oracle:thin:@localhost:1521:orcl";
- String upit = "insert into odeljenje values (?,?,?)";
- try (Connection konekcija = DriverManager.getConnection(url, "student", "student");
- PreparedStatement stat = konekcija.prepareStatement(upit);) {
- konekcija.setAutoCommit(false);
- stat.setInt(1, sifra);
- stat.setString(2, naziv);
- stat.setString(3, grad);
- int count = stat.executeUpdate();
- if(count == 1){
- konekcija.commit();
- } else{
- konekcija.rollback();
- }
- } catch (SQLException ex) {
- Logger.getLogger(TESTJDBC1.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement