while making any project in java, php ,python and any other programming language will requires database which can store that information or data entered into the project .
In this Post we are going to learn how to connect data base with project in netbeans .
we can connect sql database with java project in netbeans but we are going to use derby database in to connect in project
What is Derby Database
Derby Databse is an releational database which is embedded into the netbeans and can be easly find in the netbeans . Derby Database is compatible with netbeans versions 7.2, 7.3, 7.4 , 8.0 . And can be used with JDK version 7 or 8 .
Why to choose Derby Database
Well… sql database is quite suitable for java projects but during database setup in sql . we have to do provide more security parameters and setting database with sql will needs more memory space . into your device because you have to install mysql workbench which will requires more memory space .
But when we talk about derby database it is embedded into netbeans and can be directly used for connecting database to project . I personly used derby database in my java projects .
Steps to connect Darby Database
Step 1 -> Go to services.
Step 2 -> Double Click on Database
Step 3 -> Double click on java DB
Step 4 -> right click on sample
It will show connect
Now click to connect so it will connect to database and prepare database for us to use. It will take little time but once it connect then its ready for use.
steps for creating tables in derby database
Once you are connected to database
It will show connected -> jdbc:derby://localhost:8070/sample
Step 1-> Double click on jdbc:derby://localhost:8070/
Step 2 -> Double click on App
Step 3 -> Right click on Tables
From here you can create table for your project and link them into project from database
Or you can use create table command to create table by clicking on view data on any table which are given as examples.
Coding used for connecting Derby Database with project
Class.forName("org.apache.derby.jdbc.ClientDriver"); Connection cc=DriverManager.getConnection("jdbc:derby://localhost:8070/sample","app","app"); PreparedStatement pp=cc.prepareStatement("insert into table values(?,?)");
You can use this coding to connect your project with database
If you have any problem to connecting derby database you can contect with us .
Share your views with us .
stay connected with softwoodcoder for more coding tips and tricks .