📄 sql.java
字号:
if ( !stmt.execute( sqlstr ) ) { throw new SQLException( "SELECT * failed on table '" + TBL_CFG + "'" ); } rs = stmt.getResultSet(); if ( rs.next() ) { sqlstr = "UPDATE " + TBL_CFG + " SET " + COL_CFG_JOBHOST_UPDFREQ + " = " + jobHostUpdateFreq + " WHERE " + COL_CFG_ID + " = " + rs.getInt( COL_CFG_ID ); } else { sqlstr = "INSERT INTO " + TBL_CFG + " ( " + COL_CFG_JOBHOST_UPDFREQ + " ) VALUES ( " + jobHostUpdateFreq + " )"; } stmt.execute( sqlstr ); } catch ( SQLException sqle ) { throw sqle; } catch ( Exception ex ) { throw ex; } finally { try { if( rs != null ) { rs.close(); rs = null; } } catch ( Exception ex ) {} try { if( stmt != null ) { stmt.close(); stmt = null; } } catch ( Exception ex ) {} } } */ public static void updateCpuLoadStats( Connection conn, String wsAddr, int numUpdates, int loadTotal ) throws SQLException, Exception { Statement stmt = null; ResultSet rs = null; String sqlstr = null; int rowCount = 0; try { stmt = conn.createStatement(); sqlstr = "SELECT * FROM " + TBL_JOBHOST_STATS + " WHERE " + COL_JHSTATS_WSADDR + " = '" + wsAddr + "'"; if ( !stmt.execute( sqlstr ) ) { throw new SQLException( "SELECT * failed on table '" + TBL_JOBHOST_STATS + "'" ); } rs = stmt.getResultSet(); while ( rs.next() ) { rowCount++; } if ( rowCount > 0 ) { sqlstr = "UPDATE " + TBL_JOBHOST_STATS + " SET " + COL_JHSTATS_CPU_UPDATECOUNT + " = " + numUpdates + "," + COL_JHSTATS_CPU_LOADTOTAL + " = " + loadTotal + " WHERE " + COL_JHSTATS_WSADDR + " = '" + wsAddr + "'"; stmt.execute( sqlstr ); } } catch ( SQLException sqle ) { throw sqle; } catch ( Exception ex ) { throw ex; } finally { try { if( rs != null ) { rs.close(); rs = null; } } catch ( Exception ex ) {} try { if( stmt != null ) { stmt.close(); stmt = null; } } catch ( Exception ex ) {} } } public static CpuLoadStats getCpuLoadStats( Connection conn, String wsAddr ) throws SQLException, Exception { Statement stmt = null; ResultSet rs = null; String sqlstr = null; try { stmt = conn.createStatement(); sqlstr = "SELECT * FROM " + TBL_JOBHOST_STATS + " WHERE " + COL_JHSTATS_WSADDR + " = '" + wsAddr + "'"; if ( !stmt.execute( sqlstr ) ) { throw new SQLException( "SELECT * failed on table '" + TBL_JOBHOST_STATS + "'" ); } rs = stmt.getResultSet(); if ( rs.next() ) { return new CpuLoadStats( rs.getString( COL_JHSTATS_WSADDR ), rs.getInt( COL_JHSTATS_CPU_UPDATECOUNT ), rs.getInt( COL_JHSTATS_CPU_LOADTOTAL ) ); } return null; } catch ( SQLException sqle ) { throw sqle; } catch ( Exception ex ) { throw ex; } finally { try { if( rs != null ) { rs.close(); rs = null; } } catch ( Exception ex ) {} try { if( stmt != null ) { stmt.close(); stmt = null; } } catch ( Exception ex ) {} } } public static void deleteCpuLoadStats( Connection conn, String wsAddr ) throws SQLException, Exception { Statement stmt = null; String sqlstr = null; try { stmt = conn.createStatement(); sqlstr = "DELETE FROM " + TBL_JOBHOST_STATS + " WHERE " + COL_JHSTATS_WSADDR + " = '" + wsAddr + "'"; stmt.execute( sqlstr ); } catch ( SQLException sqle ) { throw sqle; } catch ( Exception ex ) { throw ex; } finally { try { if( stmt != null ) { stmt.close(); stmt = null; } } catch ( Exception ex ) {} } } public static void insertCpuLoadStats( Connection conn, String wsAddr, int load ) throws SQLException, Exception { Statement stmt = null; ResultSet rs = null; String sqlstr = null; try { stmt = conn.createStatement(); sqlstr = "SELECT * FROM " + TBL_JOBHOST_STATS + " WHERE " + COL_JHSTATS_WSADDR + " = '" + wsAddr + "'"; if ( !stmt.execute( sqlstr ) ) { throw new SQLException( "SELECT * failed on table '" + TBL_JOBHOST_STATS + "'" ); } rs = stmt.getResultSet(); if ( rs.next() ) { sqlstr = "UPDATE " + TBL_JOBHOST_STATS + " SET " + COL_JHSTATS_CPU_UPDATECOUNT + " = " + 1 + "," + COL_JHSTATS_CPU_LOADTOTAL + " = " + load + " WHERE " + COL_JHSTATS_WSADDR + " = '" + wsAddr + "'"; } else { sqlstr = "INSERT INTO " + TBL_JOBHOST_STATS + " ( " + COL_JHSTATS_WSADDR + "," + COL_JHSTATS_CPU_UPDATECOUNT + "," + COL_JHSTATS_CPU_LOADTOTAL + " ) VALUES ( " + "'" + wsAddr + "'" + "," + 1 + "," + load + " )"; } stmt.execute( sqlstr ); } catch ( SQLException sqle ) { throw sqle; } catch ( Exception ex ) { throw ex; } finally { try { if( rs != null ) { rs.close(); rs = null; } } catch ( Exception ex ) {} try { if( stmt != null ) { stmt.close(); stmt = null; } } catch ( Exception ex ) {} } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -