Advertisement
Guest User

Conexion a MySQL

a guest
Nov 29th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.sql.*;
  2. import javax.swing.*;
  3. public class Conexion {
  4.  
  5. Connection C;
  6.  
  7. public Connection conexion(){
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. C = DriverManager.getConnection("jdbc:mysql://localhost/proyecto","root","");
  11. if (C != null){
  12. JOptionPane.showMessageDialog(null,"Conexion establecida correctamente");
  13. }
  14. else {
  15. JOptionPane.showMessageDialog(null,"Fallo en la conexion, favor de verificar los datos");
  16. }
  17. }
  18. catch(Exception e){
  19. JOptionPane.showMessageDialog(null,e.getMessage());
  20. }
  21. return C;
  22. }
  23. Statement createStatement(){
  24. throw new UnsupportedOperationException("No soportado");
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement