Hi
Can someone please take me through how to make a connection to a MySQL database using Java in Netbeans.
I have downloaded the driver from MySQL, unzipped it to my location, and added the driver to the editor. After adding the driver, I can see it in the editor and my database along with the tables.
However, when I use Java code to make a connection, I get the following exception message:
Exception:com.m ysql.jdbc.Drive r
My code is below, it is very simple and basic. However, I would welcome guidance on how to make a proper class where I can call it from the main rather than being place in the main.
[code=java]
import java.sql.* // -- this is placed right at the top!
Connection con = null;
try
{
Class.forName(" com.mysql.jdbc. Driver").newIns tance();
con = DriverManager.g etConnection("j dbc:mysql://localhost:3306/bank","root","t riumph");
if(!con.isClose d())
System.out.prin tln("Successful ly Connected");
}catch(Exceptio n e){
System.err.prin tln("Exception: " + e.getMessage()) ;
}
}
[/code]
Can anyone help me?
Can someone please take me through how to make a connection to a MySQL database using Java in Netbeans.
I have downloaded the driver from MySQL, unzipped it to my location, and added the driver to the editor. After adding the driver, I can see it in the editor and my database along with the tables.
However, when I use Java code to make a connection, I get the following exception message:
Exception:com.m ysql.jdbc.Drive r
My code is below, it is very simple and basic. However, I would welcome guidance on how to make a proper class where I can call it from the main rather than being place in the main.
[code=java]
import java.sql.* // -- this is placed right at the top!
Connection con = null;
try
{
Class.forName(" com.mysql.jdbc. Driver").newIns tance();
con = DriverManager.g etConnection("j dbc:mysql://localhost:3306/bank","root","t riumph");
if(!con.isClose d())
System.out.prin tln("Successful ly Connected");
}catch(Exceptio n e){
System.err.prin tln("Exception: " + e.getMessage()) ;
}
}
[/code]
Can anyone help me?
Comment