Hi,
I'm beginning JDBC and I'm conversant in SQL. But I need to Connect to database and that where the problem lies. All I have done is adding mysql/j connector Jar to Netbeans project and wrote code below to test. It cannot connect to database. Also IDE throws error:
package dbclass;
//imports
import java.sql.*;
public class DBClass {
public ResultSet changeDBInfo() throws SQLException {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(this.host, this.userName, this.passWord);
if (!conn.isClosed()) {
System.out.println("Connected Successfully");
}
Statement st = conn.createStatement();
return st;
} catch (SQLException e) {
e.printStackTrace();
} finally {
conn.close();
}
return null;
}
//credentials
private String host = "jdbc:mysql://localhost:3306/mysql";
private String userName = "root";
private String passWord = "ilovejesus";
}