Cisco CiscoWorks LAN Management Solution 4.0 Technical References

Page of 142
 
3
Open Database Schema Support in CiscoWorks LAN Management Solution 4.0
OL-19283-01
  Accessing Database Views
This section contains:
Accessing Database From a Local Server
This section contains the sample code for:
Accessing Database Using Jconnect JDBC Access Method
The following is the sample code to connect to the database, using the Jconnect JDBC access method:
import java.util.Date;
import java.sql.*;
public class JdbcAccess {
private static Connection 
conn
;
private static Statement 
stmt
;
private static ResultSet 
rs
;
/**
 * @param args
 */
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
// The following information such as port, and service names are to be 
// changed based on the application database that you want to connect. 
// For example, conn = DriverManager.getConnection("jdbc:sybase:Tds:localhost:
// <ServerPort>?SERVICENAME=<DBName>","<View username>","<View password>");
conn = DriverManager.getConnection("jdbc:sybase:Tds:
localhost
:
43441
?
SERVICENAME=
cmfDb
","
lmsdatafeed
","
dbpasswd
");
System.out.println("[" + new Date() + "] INFO: Connection successful...");
//Create Statement now
stmt
 = 
conn
.createStatement();
String query = "SELECT Device_Id, Device_Display_Name, Management_IPAddress FROM 
Network_Devices";
rs
 = stmt.executeQuery(query);
while (
rs
.next()) {
System.out.println("Device_Id: " + rs.getString("Device_Id"));
System.out.println("Device_Display_Name: " + 
rs
.getString("Device_Display_Name"));
System.out.println("Management_IPAddress" + 
rs
.getString("Management_IPAddress"));
System.out.println("-----------------------------------------------------------");
}
}
}
Note
This sample code uses the Jconnect JDBC driver. You must include the Jconnect Jar file 
(NMSROOT/lib/classpath/jconn2.jar) in the CLASSPATH before you connect to the database.