Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.Statement;
- public class ConnexionBDD {
- static String url = "jdbc:mysql://localhost:8888/Peoples?autoReconnect=true&useSSL=false";
- static String login = "root";
- static String password = "";
- static Connection connection = null;
- static Statement statement = null;
- static ResultSet result = null;
- static String request = "";
- public static void main (String[] args) {
- System.out.println("will load driver");
- loadingDrive();
- System.out.println("will connect");
- connection();
- }
- public static void loadingDrive() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch ( ClassNotFoundException e ) {
- e.getMessage();
- }
- }
- public static void connection() {
- try
- {
- connection = (Connection) DriverManager.getConnection(url, login, password);
- System.out.println("Connected");
- statement = (Statement) connection.createStatement();
- result = statement.executeQuery(request);
- }
- catch ( SQLException e )
- {
- System.out.println(e.getMessage());
- } finally {
- if ( result != null ) {
- try {
- result.close();
- } catch ( SQLException ignore ) {
- }
- }
- if ( statement != null ) {
- try {
- statement.close();
- } catch ( SQLException ignore ) {
- }
- }
- if ( connection != null ) {
- try {
- connection.close();
- } catch ( SQLException ignore ) {
- }
- }
- }
- }
- }
- will load driver
- will connect
- Could not create connection to database server. Attempted reconnect 3 times. Giving up.
- result = statement.executeQuery(request);
- System.out.println(result.next());
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.6</version>
- </dependency>
- will connect
- Connected
- true
- Could not create connection to database server. Attempted reconnect 3 times. Giving up.
- static String url = "jdbc:mysql://localhost:3306/Peoples?autoReconnect=true&useSSL=false";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement