Created
June 1, 2015 22:43
-
-
Save mzdv/962c656cc0dab2db850d to your computer and use it in GitHub Desktop.
drugi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
public class JDBCTest2 { | |
public static void main(String[] args) { | |
dodajKorisnika(1300, "Milos", "Zivadinovic"); | |
} | |
private static void dodajKorisnika(int i, String milos, String zivadinovic) { | |
String url = "jdbc:oracle:thin:@localhost:1521:XE"; | |
String upit = "insert into korisnik values (?,?,?)"; | |
try { | |
Connection conn = DriverManager.getConnection(url, "system", "manager"); | |
PreparedStatement stat = conn.prepareStatement(upit); | |
conn.setAutoCommit(false); | |
stat.setInt(1, i); | |
stat.setString(2, milos); | |
stat.setString(3, zivadinovic); | |
int count = stat.executeUpdate(); | |
if(count > 0) { | |
conn.commit(); | |
} else { | |
conn.rollback(); | |
} | |
} catch (SQLException ex) { | |
Logger.getLogger(JDBCTest2.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment