This is the continuation of the previous tutorial I had, Connecting PostgreSQL to Netbeans – Part 1. Now, we will be accessing our database in PostgreSQL via our Netbeans platform.
Stretch your patience with this one, especially in the coding part.
1. As you open your Netbeans, got to File > New Project > Categories: Java > Projects: Java Application. Then click Next.
2. Fill in your Project Name, then click Finish.
3. Go to your project, mine is named trylang. Right click Libraries, and Add Library.
4. A pop-up will appear, choose PostgreSQL JDBC Driver.
5. Then clear the source file and fill it with the code that will eventually connect your database to your Netbeans. The code can be downloaded in this file hosting site. Warning: you have to replace the variables in the code with your own in your database; it’s because it will surely cause errors.
6. Finally, after pasting and editing the code, Run the code. Then you will get a pop-up window displaying the content of your table you created in PostgreSQL.
There you have it, you’ve just accessed your database in PostgreSQL using Netbeans. You could actually edit the columns of your table, and rerun the source code. You will then get an updated call.
Domo arigato! 😄