ploofah ploofah - 1 year ago 127
Java Question

mysql database connection in java netbeans?

im trying to develop a simple database web application in netbeans, but im 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");`
} }
catch(Exception e){ System.out.println("notconnected");

please help!!

Answer Source

You need to call instance of the mysql driver too. Add


before Your conn= statement.