If you want to connect database with your java application then first to need a database. First to create database using Netbeans services tab. This tab available under Windows tab. You can also select this tab by using shortcut CTRL+ 5.
2. Fill fields which are shown under diagram.
3. After filling the form, you have to create database successfully.
4. Right Click on your connection string name, select properties for copy the database URL.
- Expand the databases tab, select "Create Database." option.
3. After filling the form, you have to create database successfully.
4. Right Click on your connection string name, select properties for copy the database URL.
5. Copy Database URL, which is used further.
6. Create a new java project under projects tab.
7. Add a Library in the "Libraries" section of your project.
8. Select Java DB Driver under Add Library section.
9. Open your .java file which is exists in java packages folder of your project.
10. Create a another class object, which is exists in same package.
11. Now, Open the object class, create constructor in it.
12. paste the code under the constructor.
Connection conn=DriverManager.getConnection("jdbc:derby://localhost:1527/jk", "jk", "jk");
System.out.println("connection created");
Here we have three parameters in getConnection method.
First refer to database url ; according to 5th step.
Second : Username
Third : password.