Advertisement
Guest User

Untitled

a guest
Oct 29th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1.  
  2. package sqlaplikacija;
  3. import java.sql.*;
  4. public class Konekcija {
  5. public static void main(String[] args)
  6. {
  7. try
  8. {
  9.  
  10. String dbUrl="jdbc:mysql://localhost:3309/itsbaza";
  11. String user= "root";
  12. String pass= "";
  13.  
  14. Class.forName("com.mysql.jdbc.Driver");
  15. Connection veza= DriverManager.getConnection(dbUrl,user,pass);
  16. Statement st=veza.createStatement();
  17. String upit="select * from student";
  18. try {
  19. ResultSet rezultat=st.executeQuery(upit);
  20. System.out.println("Ispravljacki program (drajver) je ucitan!");
  21. while(rezultat.next())
  22. {
  23. System.out.println(rezultat.getString("ime")+ " " +
  24. rezultat.getString("prezime") + " " +rezultat.getString("brIndexa")
  25. );
  26. };
  27. String upit2="delete from student where ime = 'Pera'";
  28. PreparedStatement pstate= veza.prepareStatement(upit2);
  29.  
  30. try {
  31. pstate.executeUpdate();
  32. } catch (SQLException e) {
  33. System.out.println("Izuzetak. " + e);
  34. }
  35.  
  36. } catch (Exception e) {
  37. System.out.println("Pogresan upit");
  38. }
  39.  
  40.  
  41. }
  42. catch ( SQLException ex)
  43. {
  44. System.out.println("Izuzetak. " + ex);
  45. }
  46. catch ( ClassNotFoundException e)
  47. {
  48. System.out.println("Upravljacki program nije caitan." + e);
  49. }
  50.  
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement