Home > Articles

  • Print
  • + Share This
Like this article? We recommend

Database and Connection Creation

At this stage, the Derby driver should be loaded. We can now create the database and make a connection to it. It can be done in one step as illustrated in Listing 7.

Listing 7 Database and connection creation

Connection conn = null;
Properties props = new Properties();
props.put("user", "user1");
props.put("password", "user1");
conn = DriverManager.getConnection(protocol + dbName + ";create=true", props);

In Listing 7, a Connection object is created and set to null. Next, a Properties object is created to store a user account for database access. Then, the database called dbName is created based on the user credentials contained in the props object. After this code executes, you should see the appearance of the database files in the folder indicated by the value of dbName; that is, TestDB.

  • + Share This
  • 🔖 Save To Your Account