Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.mysql.jdbc.Statement;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class DatabaseConnection {
- public static void main(String[] args) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
- dbConnection();
- }
- private static void dbConnection() throws ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Driver loaded");
- String url = "jdbc:mysql://localhost:3306/atomspace_db?autoReconnect=true&useSSL=false";
- String username = "root";
- String password = "************";
- System.out.println("Connecting database...");
- Connection connection = DriverManager.getConnection(url, username, password);
- Statement stmt = (Statement) connection.createStatement();
- stmt = (Statement) connection.createStatement();
- ResultSet rs = stmt.executeQuery("Select * from students");
- connection.close();
- }
- }
Add Comment
Please, Sign In to add comment