Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws Exception {
- MySQLAccess dao = new MySQLAccess();
- dao.readDataBase();
- }
- -------------
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Date;
- public class MySQLAccess {
- public void readDataBase() {
- String url = "jdbc:mysql://mysql.wmi.amu.edu.pl:3306/s434596_javapizza";
- String userName = "s434596";
- String password = "tinwordpress123";
- //MySQLAccess.forName(driver).newInstance();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException s) {
- throw new IllegalStateException("Cannot find the driver in the classpath!", s);
- }
- System.out.println("Connecting database...");
- try (Connection connection = DriverManager.getConnection(url, userName, password)) {
- System.out.println("Database connected!");
- } catch (SQLException e) {
- throw new IllegalStateException("Cannot connect the database!", e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement