Advertisement
Guest User

Untitled

a guest
May 30th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. package javaapplication1;
  2. import java.sql.*;
  3. import java.util.*;
  4. import java.io.FileInputStream;
  5.  
  6. public class JavaApplication1 {
  7.    
  8.     public static void main(String[] args) {
  9.         String url="jdbc:mysql://localhost:3306/test";
  10.         String driver="com.mysql.jdbc.Driver";
  11.         String user="root";
  12.         String pass="";
  13.         Connection conn=null;
  14.         Statement st=null;
  15.        
  16.         try {
  17.             Class.forName("com.mysql.jdbc.Driver");
  18.  
  19.             conn=DriverManager.getConnection(url, user, pass);
  20.             conn.setAutoCommit(false);
  21.             st = conn.createStatement();
  22.            
  23.             st.executeUpdate("DELETE FROM student WHERE godina=4");
  24.             conn.commit();
  25.            
  26.             st.close();
  27.             conn.close();
  28.         }
  29.         catch(Exception e) {
  30.             e.printStackTrace();
  31.             try {
  32.                 if(conn!=null)
  33.                     conn.rollback();
  34.             }
  35.             catch(Exception se)
  36.             {
  37.                 se.printStackTrace();
  38.             }
  39.            
  40.         }
  41.  
  42.     }
  43.    
  44.     private static void ispisiRetke(ResultSet rs) throws SQLException {
  45.         while(rs.next()) {
  46.             int jmbag=rs.getInt("jmbag");
  47.             String prezime=rs.getString("prezimes");
  48.             String ime=rs.getString("imes");
  49.             int godina=rs.getInt("godina");
  50.             System.out.printf("%d, %s, %s, %d\n", jmbag, prezime, ime, godina);
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement