Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication1;
- import java.sql.*;
- import java.util.*;
- import java.io.FileInputStream;
- public class JavaApplication1 {
- public static void main(String[] args) {
- String url="jdbc:mysql://localhost:3306/test";
- String driver="com.mysql.jdbc.Driver";
- String user="root";
- String pass="";
- Connection conn=null;
- Statement st=null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conn=DriverManager.getConnection(url, user, pass);
- conn.setAutoCommit(false);
- st = conn.createStatement();
- st.executeUpdate("DELETE FROM student WHERE godina=4");
- conn.commit();
- st.close();
- conn.close();
- }
- catch(Exception e) {
- e.printStackTrace();
- try {
- if(conn!=null)
- conn.rollback();
- }
- catch(Exception se)
- {
- se.printStackTrace();
- }
- }
- }
- private static void ispisiRetke(ResultSet rs) throws SQLException {
- while(rs.next()) {
- int jmbag=rs.getInt("jmbag");
- String prezime=rs.getString("prezimes");
- String ime=rs.getString("imes");
- int godina=rs.getInt("godina");
- System.out.printf("%d, %s, %s, %d\n", jmbag, prezime, ime, godina);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement