Showing posts with label javadb. Show all posts
Showing posts with label javadb. Show all posts

Tuesday, 27 December 2011

Server tool to start JavaDB in a network client environment

To start JavaDB:
Set the Path environment variable to include the <JAVA_HOME>/db/lib directory.
Open the command prompt and type the following command:


java �jar derbyrun.jar server start
 
Ping JavaDB 
Stop JavaDB 

Working with Tables

Use the Create Table SQL command to create a new table in a database.


Create table employee (name varchar(30),address varchar(50));

Viewing and Switching Connections

Show Connections command lists the active connections established with JavaDB.
You can then use the Set connection command to switch to a different connection.
To view and switch between connections:


show connections;

Using the ij Tool

The ij tool enables you to connect to a running JavaDB server and execute scripts and queries against a database.
The command to use the ij tool is:


java �jar derbyrun.jar ij


Commands of the ij Tool
CommandDescriptionDriverLoads the specified JDBC driver.ProtocolSets the specified protocol to use for connecting to a database.ConnectEstablishes a connection with a database.Set ConnectionSwitches from the existing connection to a different connection specified with a connection name.Show ConnectionsLists all active connections.DisconnectDisconnects the current connection, a connection specified by a connection name, or all active connections.Show SchemasLists all schemas present in the current database.Show TablesLists all tables present in the current database.Show ViewsLists all views present in the current database.Show ProceduresLists all stored procedures present in the current database.Show IndexesLists all indexes present in a specified table.DescribeDisplays information about columns, such as column name and data type, for a specified table.rumitCommits the current transaction.RollbackRolls back the current transaction.

To view run time information for JavaDB

java �jar derbyrun.jar server runtime

Stop JavaDB

java �jar derbyrun.jar server shutdown

Ping JavaDB

The JavaDB Environments

Embedded: Allows only a single application to access a database at one time.
In the embedded environment, no network access occurs.
When you load a JDBC driver from a Java program, JavaDB automatically starts in the embedded environment.
Client/server: Allows multiple applications to connect to JavaDB over the network.
To start JavaDB in the client/server environment, you need to use the server command line tool of JavaDB.

The JavaDB Directory Structure

When you install Java SE 6, JavaDB installs in the db directory of JAVA_HOME.
The db directory contains the following subdirectories:
  1. demo: Contains sample programs and scripts to use JavaDB.
  2. lib: Contains the JavaDB JAR files. You need to use the JavaDB JAR files to start, stop, and access JavaDB.
  3. frameworks: Contains scripts for setting up the environment to use JavaDB in different environments.

Ping JavaDB.

The command to ping JavaDB is:


java �jar derbyrun.jar server ping
java �jar derbyrun.jar server ping 192.168.0.1 1555

JavaDB URLs

To connect to an existing JavaDB database using the embedded driver:


jdbc:derby:<databaseName>;<URLAttributes>


  1. host: Specifies the computer name or Internet Protocol address where Java DB is running. If Java DB is running on the same computer as that of the client, you can use localhost or 127.0.0.1 as the value of the host option.
  2. Port: Specifies the port number used by JavaDB to accept incoming requests.
  3. databaseName: Represents the name of the database to connect with.

JavaDB Tools

Java SE 6 contains various tools that you can use to start, stop, access, and administer JavaDB.
Some of the JavaDB tools are:
  1. server: Starts the JavaDB database.
  2. ij Represents a JDBC scripting tool.
  3. You can use ij to run scripts against a JavaDB database.
  4. You can also use ij to run SQL queries.
  5. You can use ij to access JavaDB running in both the embedded and client/server environments.
  6. sysinfo: Displays information about the JavaDB version and the environment.
  7. dblook: Generates and stores the Data Definition Language (DDL) to a file.
  8. In Java SE 6, the server, ij, sysinfo, and dblook tools are packaged in the derbyrun.jar file.
  9. You can locate the derbyrun.jar file in the <JAVA_HOME>/db/lib directory.

JavaDB Drivers

Based on the environment in which JavaDB is running, Java SE 6 contains two drivers for accessing JavaDB. They are:
Embedded driver enables you to access JavaDB databases running in the embedded environment.
The org.apache.derby.jdbc.EmbeddedDriver class implements the embedded driver.
Network client driver enables you to access the JavaDB database running in the client/server environment.
The org.apache.derby.jdbc.ClientDriver class implements the network client driver.