- Derby: A Database for All Seasons
- What Is Derby?
- How to Use Derby
- Setting Up Your CLASSPATH
- Testing Your Setup
- Running Your First Derby Program
- Derby Application Components
- Derby Application Startup
- Loading the Derby Driver
- Database and Connection Creation
- Statement Creation
- Table Creation
- Table Access
- Running the Code
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.