Cisco Cisco Firepower Management Center 2000 Guía Del Desarrollador
2-9
FireSIGHT System Database Access Guide
Chapter 2 Setting Up Database Access
Connecting to the Database Using a Custom Program
Connecting the program to the database
Your program must obtain a JDBC connection object before it can submit queries. Use the
DriverManager.getConnection
method as follows to establish the connection and get the connection
object:
Connection conn = DriverManager.getConnection(“jdbc:vjdbc:rmi://my_dc:2000/VJdbc,eqe”,
“user”, “password”);
where
my_dc
is either the FQDN or the IP address for the Defense Center,
user
is the database access
user account name, and
password
is the account password.
Querying the data in the Cisco tables
Create an SQL query object to submit the query and assign the retrieved records to a result set, as
follows:
follows:
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(“sql”);
where
sql
is the SQL query. See
for supported SQL functions.
Producing the results of a table query
With the result set (
rs
) generated by the above query, you can output the fields as follows:
while(rs.next())
{
for(int i=1; i<= md.getColumnCount(); i++)
{
System.out.print(rs.getString(i) + " ");
}
System.out.print("\n");
}
Getting schema information
Your program can list the tables in the database, as follows:
DatabaseMetaData metaData = conn.getMetaData();
ResultSet tables = meta.getTables(null, null, null, null);
while (tables.next())
{
System.out.println(tables.getString("TABLE_NAME"));
}
Your program can list a table’s columns, as follows:
ResultSet columns = metaData.getColumns(null, null, "table_name", null);
where
table_name
is the name of the database table.
Running the Application
Before you run your application, you must set the
CLASSPATH
on the client computer to include the current
directory and the locations of your application’s JAR files.
If you downloaded and unpacked the ZIP package for Database Access as noted in
, update the
CLASSPATH
as follows: