Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Java program will not connect to mySQL database
- public class Version {
- public static void main(String[] args) {
- Connection con = null;
- Statement st = null;
- ResultSet rs = null;
- //String url = "jdbc:mysql://127.0.0.1/sakila";
- String url = "jdbc:mysql://localhost:3306/sakila";
- String user = "root";
- String password = "root";
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection(url, user, password);
- st = con.createStatement();
- rs = st.executeQuery("select * from ACTOR;");
- System.out.println("test");
- if (rs.next()) {
- System.out.println(rs.getString(1));
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- } finally {
- try {
- if (rs != null) {
- rs.close();
- }
- if (st != null) {
- st.close();
- }
- if (con != null) {
- con.close();
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- }
- Class.forName("org.mysql.Driver");
- Class.forName("com.mysql.jdbc.Driver").newInstance();
Add Comment
Please, Sign In to add comment