Issue
I am trying to develop a simple database web application in netbeans, but I am getting a problem at database connection , my database is not being connected for some reason, the username password and hostname are correct and the mysql workbench is registered with my netbeans as well.
Is there something wrong with this code?
public class test {
public static void main(String args[]) {
Connection conn=null;
try{ `conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/crud_news", "root","zunairaabira");`
if(conn!=null){
System.out.println("successful");
} }
catch(Exception e){ System.out.println("notconnected");
}}}
please help!!
Solution
You need to call instance of the mysql driver too. Add
Class.forName("com.mysql.jdbc.Driver").newInstance();
before Your conn= statement.
Answered By - Mirhawk
Answer Checked By - Timothy Miller (JavaFixing Admin)