-
-
Save uncoded-ro/76142f06f0e4b8976e466a6ffea787fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ro.virtualcampus.db; | |
import java.sql.*; | |
public class JDBCTest { | |
private static Connection conn = null; | |
private String database = null; | |
private String user = null; | |
private String password = null; | |
private String hostname = null; | |
public JDBCTest(String database, String hostname, String user, String password) { | |
this.database = database; | |
this.hostname = hostname; | |
this.user = user; | |
this.password = password; | |
} | |
public void connect() { | |
try { | |
Class.forName("com.mysql.cj.jdbc.Driver"); | |
conn = DriverManager.getConnection("jdbc:mysql://" + | |
hostname + "/" + database, user, password); | |
System.out.println("Conexiunea stabilita!"); | |
} catch (SQLException e) { | |
System.out.println("Probleme la conectare!"); | |
System.out.println(e.getMessage()); | |
} catch (Exception e) { | |
System.out.println("Probleme la incarcarea driver-ului!"); | |
System.out.println(e.getMessage()); | |
} | |
} | |
public void disconnect() { | |
try { | |
if (conn != null) | |
conn.close(); | |
System.out.println("Deconectare reusita!"); | |
} catch (SQLException e) { | |
System.out.println("Probleme la deconectare!"); | |
} | |
} | |
public static void main(String[] args) { | |
JDBCTest jdbc = new JDBCTest("sakila", "data.virtualcampus.ro", "airman", "parola"); | |
jdbc.connect(); | |
jdbc.disconnect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment