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 JDBCTest2 {
- public static void main(String[] args) {
- dodajOdeljenje(100 , "Neko odeljenje", "Beograd");
- }
- private 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 conn =
- DriverManager.getConnection(url, "student", "student");
- PreparedStatement ps = conn.prepareStatement(upit);
- ){
- ps.setInt(1, sifra);
- ps.setString(2, naziv);
- ps.setString(3, grad);
- int br = ps.executeUpdate();
- conn.setAutoCommit(false);
- if(br > 0) {
- conn.commit();
- }else {
- conn.rollback();
- }
- } catch (SQLException ex) {
- Logger.getLogger(JDBCTest2.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement