public int countAssets() throws RemoteException, MXException { MXServer mxServer = MXServer.getMXServer(); ConnectionKey conKey = mxServer.getSystemUserInfo().getConnectionKey(); Connection con = mxServer.getDBManager().getConnection(conKey); int c = 0; try { Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select count(*) from asset"); while (rs.next()) c = rs.getInt(1); rs.close(); stmt.close(); con.commit(); } catch (SQLException e ) { throw new MXApplicationException("SQLException caught", e.getMessage()); } finally { mxServer.getDBManager().freeConnection(conKey); } return c; }
public int countAssets() throws RemoteException, MXException { MXServer mxServer = MXServer.getMXServer(); ConnectionKey conKey = mxServer.getSystemUserInfo().getConnectionKey(); DBShortcut dbs = new DBShortcut(); dbs.connect(conKey); int c = 0; try { ResultSet rs = dbs.executeQuery("select count(*) from asset"); while (rs.next()) c = rs.getInt(1); rs.close(); dbs.commit(); } catch (SQLException e ) { throw new MXApplicationException("SQLException caught", e.getMessage()); } finally { dbs.close(); } return c; }
ConnectionKey conKey = getUserInfo().getConnectionKey(); Connection con = getMboServer().getDBConnection(conKey);
Labels: advanced, connection, database, java, jdbc