0% found this document useful (0 votes)
59 views1 page

Package Import Import Import Import

This Java code defines a 'conexion' class that is used to connect to a MySQL database called 'dbcalibracion' located at 127.0.0.1. The class stores the database name, URL, username and password as properties. It contains a 'conectar()' method that returns a Connection object by loading the MySQL driver, and calling getConnection on the DriverManager using the URL, username and password properties. Any errors connecting are caught and displayed in a JOptionPane dialog box.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views1 page

Package Import Import Import Import

This Java code defines a 'conexion' class that is used to connect to a MySQL database called 'dbcalibracion' located at 127.0.0.1. The class stores the database name, URL, username and password as properties. It contains a 'conectar()' method that returns a Connection object by loading the MySQL driver, and calling getConnection on the DriverManager using the URL, username and password properties. Any errors connecting are caught and displayed in a JOptionPane dialog box.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

26/2/2018 conexion.

java

C:\Users\GioMemo\Documents\NetBeansProjects\SistemaCalibracion\src\Logica\conexion.java

1 /*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6 package Logica;
7
8 import java.sql.Connection;
9 import java.sql.DriverManager;
10 import java.sql.SQLException;
11 import javax.swing.JOptionPane;
12
13 /**
14 *
15 * @author GioMemo
16 */
17 public class conexion {
18 public String db="dbcalibracion";
19 public String url="jdbc:mysql://127.0.0.1/"+db;
20 public String user="root";
21 public String pass="";
22
23 public conexion() {
24 }
25
26 public Connection conectar(){
27 Connection link=null;
28
29 try {
30 Class.forName("org.gjt.mm.mysql.Driver");
31 link=DriverManager.getConnection(this.url, this.user, this.pass);
32 } catch (ClassNotFoundException | SQLException e) {
33 JOptionPane.showConfirmDialog(null, e);
34 }
35 return link;
36 }
37
38 }
39

file:///C:/Users/GioMemo/Desktop/conexion.html 1/1

You might also like