Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySQL_Test {
- public static void main(String[] args) {
- MySQL db = new MySQL();
- try {
- db.MySQLConnection("root","","");
- } catch (Exception ex) {
- Logger.getLogger(MySQL_Test.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- public class MySQL {
- private static Connection Conexion;
- public void MySQLConnection(String user, String pass, String db_name) throws Exception {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + db_name, user, pass);
- JOptionPane.showMessageDialog(null, "Se ha iniciado la conexión con el servidor de forma exitosa");
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement