Netcool Object Server api - java

Running Netcool 7.3.1. Looking for simple api to access Object Server Tables. I've already done the run an SQL command from nco_sql, and scraped the output into a C# data table, but wondering if there was some type of api that I could use for either C# or Java to access table data?

If you can use a more up-to-date version of Omnibus, you can use the built-in HTTP / REST API.
http://www-01.ibm.com/support/knowledgecenter/SSSHTQ_8.1.0/com.ibm.netcool_OMNIbus.doc_8.1.0/omnibus/wip/api/concept/omn_api_http_overview.html?lang=en

You may need to use sybase database adapter so far I have used below three ways to query netcool object server:
Free TDS - This is free sybase client.
Jconn3 - this is paid sybase client, but if you are using WebGUI/Impact, this driver comes with TIP.
nco_sql - here you may need to create a file with query and then pass it to nco_sql. This require extra effort to parse column wise information as output will be on console.
I prefer jconn3, simple and similar to jdbc driver, you only need this jar in classpath.

You can write your own java program to connect to Objectserver by simply initiating
//Load Sybase Driver
Class.forName("com.sybase.jdbc3.jdbc.SybDriver");
String url = "jdbc:sybase:Tds:" + host + ":" + port;
con = DriverManager.getConnection(url, user, pass);
Execute Statements
Statement stat = conn.createStatement();
ResultSet result = stat.executeQuery("Select count(*) from alerts.status");;`

Related

How to "package" an SQL database

I am looking for a way to save an SQL database and then reference it by means other than localhost which would not work because it is being used on other computers.
I realize that my terminology may not be correct in asking for a means to "package" an SQL database however I am not very sure how to put my desire such a concise title.
I have a database that I created through mySQL here: http://gyazo.com/fcac155a60c0d2587442c3e4807ef98a
I can access this database with no problems through the following code...
try
{
//Get connection
Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/term_database","root", "_cA\"#8X(XHm+++E");
//**********
//Connection myConn = DriverManager.getConnection("jdbc:mysql:translationDatabase","root", "_cA\"#8X(XHm+++E");
//**********
//create statement
Statement myStmt = myConn.createStatement();
//execute sql query
ResultSet myRs = myStmt.executeQuery("select * from terms WHERE idNumber=" +termNumber);
//process result set
while(myRs.next()){
term= (myRs.getString(language));
}
}
catch (Exception exc)
{
exc.printStackTrace();
}
However, I assume that my users will be on different computers and so a "//localhost" reference will not work. They do not have access to the internet either. So I aim to include the database in my program's files to be downloaded with the software or to include it in the jar. I was not able to find any means to do that online. The code I surrounded with *'s was an attempt to reference translationDatabase.sql which I saved through the program mySQL into my software's directory but it did not work as shown here: http://gyazo.com/e9d4339435dedecab4e7ad960e9b13b6
To recap: I am looking for a way to save an SQL database and then reference it by means other than localhost which would not work because it is being used on other computers.
The idiomatic terminology is "embedded" or "serverless" database.
There are several pure-java solutions. There is also the popular SQLite, which you can manipulate via its command line client, or via a third-party JDBC driver (example 1, example 2)
Any of the above solutions will require that you convert your existing MySQL database to the target system..
Alternatively, you may consider bundling your application with MySQL server (possibly with an automated installation process, so that installation is invisible to the end-user).

How to connect two database through JDBC? Is it possible?

I have tried to connect the mysql database with the frontend with the help of JDBC driver. But i dont know how acna we implement connectivity to connect the two different databases with each other with the help of JDBC driver.
You can create two connections. One for the first database and the other for the second database. You can send commands to the first database using the first connection and you can send commands to the second database using the second connection. Your application will serve the purpose of connecting the two databases as you can select rows from one database, parse them and insert the resulting records into the other.
There is no magic in JDBC that allows you to 'connect the two database with each other'. You need to code this yourself. You create two connections, one for each database and then you write the queries and transformations to get your data from database 1 to database 2.
try (
Connection connectionToDb1 = DriverManager.getConnection(
"jdbc:firebirdsql://serverA/database1", "username", "password");
Connection connectionToDb2 = DriverManager.getConnection(
"jdbc:firebirdsql://serverB/database2", "username", "password");
Statement selectFrom1 = connectionToDb1.createStatement();
ResultSet rsFrom1 = selectFrom1.executeQuery(
"SELECT columnA, columnB FROM tableX");
PreparedStatement insertTo2 = connectionToDb2.prepareStatement(
"INSERT INTO tableY(column1, column2) VALUES (?, ?)");
) {
while (rsFrom1.next()) {
insertTo2.setString(1, rsFrom1.getString("columnA"));
insertTo2.setString(2, rsFrom1.getString("columnB"));
insertTo2.executeUpdate();
}
}
Note that this isn't a complete example: for production purposes you would disable auto commit, and use batch updates.
There are tools that can do this for you, but tool and library suggestions are off topic on SO, but I'd suggest you search for ETL (or extract, transform, load), or maybe for datapump.

How to get the default schema of a SQL connection?

From within a java code - where I already have a connection to a database - I need to find the default schema of the connection.
I have the following code that gives me a list of all schemas of that connection.
rs = transactionManager.getDataSource().getConnection().getMetaData().getSchemas();
while (rs.next()) {
log.debug("The schema is {} and the catalogue is {} ", rs.getString(1), rs.getString(2));
}
However, I don't want the list of all the schemas. I need the default schema of this connection.
Please help.
Note1: I am using H2 and DB2 on Windows7 (dev box) and Linux Redhat (production box)
Note2: I finally concluded that it was not possible to use the Connections object in Java to find the default schema of both H2 and DB2 using the same code. I fixed the problem with a configuration file. However, if someone can share a solution, I could go back and refactor the code.
Please use connection.getMetaData().getURL() method which returns String like
jdbc:mysql://localhost:3306/?autoReconnect=true&useUnicode=true&characterEncoding=utf8
We can parse it easily and get the schema name. It works for all JDBC drivers.

How to connect to remote database through DB link using JDBC?

I need to connect to a remote database using Database link using JDBC commands.
How can it be done?
If you already have the dblink setup, you can utilize it in your SQL (sent via jdbc) by addressing the required tables like such:
select * from SCHEMA.TABLE#DBLINK_NAME
Using this query inside of your java would look something like this
public ResultSet execQuery() throws SQLException, ClassNotFoundException{
//Load the database driver
Class.forName("oracle.jdbc.OracleDriver");
//Create connection to the database
Connection myConnection = DriverManager.getConnection(connectURL,userName,userPwd);
//Create a statement link to the database for running queries
Statement myQuery = myConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//Create a resultSet to hold the returned query information
ResultSet myQueryResults = myQuery.executeQuery("select * from SCHEMA.TABLE#DBLINK_NAME");
return myQueryResults;
}
*java & oracle assumed
If you are asking about how to use JDBC to create a link between the DB you are talking to and another one, then it is "just SQL" that you (presumably) would execute in the same way as you would any other SQL statement. (If you tell us which DB you are using, we could talk about the actual SQL you need to execute.)
Otherwise, I don't think this makes sense. A DB link / Database link is a link from one database to another. But JDBC is for talking to a database from a Java client. It makes no sense (to me) to use DB link to connect a JDBC client to a database.
Please take a look at orajdbclink, on sourceforge
I am planning to to connect my oracle plsql sources to phoenix skin of hbase. It seems to me the unique way to create a connector between oracle and hbase for the moment...

Retrieving MYSQL Database structure information from Java

I'm trying to do with java and mysql the same I am used to with .net and SQL server:
By using Microsoft.SqlServer.Management.Smo I can access database structure information from my instance ( server name, table structure, columns, datatype, description, default value)
I tried to find to do the same with Java + MYSQL but it seems it is not so popular
any directions?
thanks
Ed
The simplest way to accomplish it is by retrying the connection metadata, first you open a connection:
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "user","****");
DatabaseMetaData metaData = conn.getMetaData();
then start navigating through the metadata, you can check the available operations in DatabaseMedata
DatabaseMetaData will be useful for your requirement.
please also check nearly similar stackoverflow question
use the DatabaseMetadata for get database related information.
Database Metadata

Categories