Is it possible to write a pure sql statement for Maximo using Java? At the moment I use myObj.setWhere("employee = 'brian'");
But I'd like to do:
myObj.xxx("select * from employee where name = 'brian'");
is there such a function?
Is it possible to write a pure sql statement for Maximo using Java? At the moment I use myObj.setWhere("employee = 'brian'");
But I'd like to do:
myObj.xxx("select * from employee where name = 'brian'");
is there such a function?
While I would strongly discourage it, you can run direct SQL statements without needing to deal with the driver manager yourself. You can just request a connection from Maximo.
Most of the time (like in the below examples), Maximo already provides the functionality for the statement you would run, or you will be selecting a subset of fields that Maximo, as a basic ORM, can't handle. In those cases, you wouldn't want to do this.
Connection con = null;
try {
con = getMboServer().getDBConnection(getUserInfo().getConnectionKey());
PreparedStatement stmnt = con.prepareStatement("update asset set description = 'Hello World'");
stmnt.execute();
stmnt = con.prepareStatement("select count(*) from asset");
if (stmnt.execute()) {
ResultSet results = stmnt.getResultSet();
if (results.next()) {
int count = results.getInt(1);
}
}
} catch (SQLException e) {
logger.error("There was an 'SQLException' exception while getting the count of assets; The error is:\n", e);
} finally {
if (con != null) {
getMboServer().freeDBConnection(getUserInfo().getConnectionKey());
}
}
I think Maximo will work with the java.sql package, which can be used like so:
import java.sql.*
String connectionString = "Your JDBC connection string here";
Connection conn = java.sql.DriverManager.getConnection(connectionString);
String sQuery = "SELECT SAMPLE_COLUMN FROM SAMPLE_TABLE";
Statement stmt= conn.createStatement();
ResultSet result = stmt.executeQuery(sQuery);
Read here how to parse through a ResultSet to get the information you want: http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html