Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. /**
  2. *
  3. * @author bruno
  4. */
  5. package test;
  6.  
  7. import java.sql.*;
  8.  
  9.  
  10. public class Main {
  11.  
  12. /**
  13. * @param args the command line arguments
  14. */
  15. public static void main(String[] args){
  16. try{
  17. Class.forName("com.mysql.jdbc.Driver");
  18. Connection con = DriverManager.getConnection("jdbc:mysql://localhost/prositjava1","bruno", "bruno");
  19. Statement stmt = con.createStatement();
  20. ResultSet res= stmt.executeQuery("SELECT * FROM test");
  21. while(res.next()){
  22. System.out.println("ID : " + res.getInt(1));
  23. System.out.println("Nom: " + res.getString(2));
  24. }
  25. System.out.println("\nInsertion d'éléments :");
  26. int ret = stmt.executeUpdate("INSERT INTO test VALUES (350, \"Papa Noël\")");
  27. System.out.println("Nbr lignes modifiés : " + ret);
  28. }catch(Exception e){
  29. System.out.println("Problème de pilote : " + e);
  30. }
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement