Initially, it is essential to set up the database connection.
STEP 1:
Create a database in phpmyadmin and create the required table.
STEP 2:
Set up a new connection in Net Beans.
1. Right Click on Databases(Services tab) -> Select New Connection
3. Enter the name of your database -> TEST CONNECTION
4. If you see the below added to your services, then the connection has been set up successfully.
STEP 3:
Add a library to the net beans project as below.
STEP 4: Creating the Database Connect Class
1. Create a new package under the project and create a new class called 'DBconnect' under that package.
2. DBconnect class should look like below.
In the line,
con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","");
The highlighted path can be optained from the services pane where we established a connection to the relevant DB.
Now, whenever you need to connect to the database, all you have to do is call this connect method.
STEP 1:
Create a database in phpmyadmin and create the required table.
STEP 2:
Set up a new connection in Net Beans.
1. Right Click on Databases(Services tab) -> Select New Connection
2. Select MySQL -> Select Next
3. Enter the name of your database -> TEST CONNECTION
4. If you see the below added to your services, then the connection has been set up successfully.
STEP 3:
Add a library to the net beans project as below.
STEP 4: Creating the Database Connect Class
1. Create a new package under the project and create a new class called 'DBconnect' under that package.
2. DBconnect class should look like below.
con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","");
The highlighted path can be optained from the services pane where we established a connection to the relevant DB.
Now, whenever you need to connect to the database, all you have to do is call this connect method.
Comments
Post a Comment