Advertisement
Guest User

Untitled

a guest
May 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. package agenda;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9.  
  10. class MyConnection {
  11.  
  12. private Connection con;
  13. Statement stmt;
  14. String url = "jdbc:mysql://127.0.0.1:3306/agenda";
  15. String user = "root";
  16. String password = "aluno@etep";
  17.  
  18. public MyConnection() throws ClassNotFoundException {
  19.  
  20. try {
  21. Class.forName("com.mysql.jdbc.Driver");
  22. con = DriverManager.getConnection(url, user, password);
  23. stmt = con.createStatement();
  24. System.out.println("Conectado com sucesso!");
  25.  
  26. } catch (SQLException ex) {
  27. Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE, null, ex);
  28. }
  29.  
  30. try{
  31. stmt.execute("INSERT INTO contato VALUES (NULL,'Evandro','12','3211-9640');");
  32. }catch(SQLException e){
  33. System.out.println("Error: "+ e.getMessage());
  34. }
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement