我需要在web机器当掉前, 记录到数据库服务器的SHOW   INNODB   STATUS 所有信息(死锁导致web机器的程序当掉)。我在mysql图形工具里执行
SHOW   INNODB   STATUS   
发现得不到返回信息。  但是在linux命令行,可以得到完整的返回信息。问如何用java代码得到SHOW   INNODB   STATUS 命令的返回值

解决方案 »

  1.   

    和正常查询相同处理。比如C中  mysql_query("SHOW   INNODB   STATUS")
      

  2.   

    mysql图形工具里执行 
    SHOW  INNODB  STATUS  
    发现得不到返回信息  发现得到是空值???
      

  3.   

    用的java 你的问题是什么?是用java 还是 mysql query browser ?
      

  4.   

    程序代码里得到 SHOW  INNODB  STATUS  
    所有返回值
      

  5.   

    如果在程序中,则直接与普通select 查询相同的处理!
      

  6.   

    应该是直接调用result即可以获取到了的。
      

  7.   

    package com.test;import java.sql.DriverManager;import com.mysql.jdbc.Connection;
    import com.mysql.jdbc.ResultSet;
    import com.mysql.jdbc.Statement;public class ShowInnodbStatus {
    public static void main(String[] args){
       Connection con = null;
       try{
      //1.加载驱动
      String driverName = 
     "com.mysql.jdbc.Driver";
          Class.forName(driverName);
      //2.连接数据库
      String url = 
        "jdbc:mysql://127.0.0.1:3306/wxj";
      String userName = "root";
      String pwd = "root";
              con = (Connection) DriverManager.getConnection(url,userName,pwd);
          Statement st=(Statement) con.createStatement();
          ResultSet rs=(ResultSet) st.executeQuery("show innodb status");
          while(rs.next()){
           System.out.println(rs.getString(1));
          }
       } catch(Exception e){
      e.printStackTrace();
       }finally{
      try{
            con.close();
      }catch(Exception ex){
        ex.printStackTrace();
      }
       }
    }
    }
      

  8.   

    需要的, 请问楼上,System.out.println(rs.getString(1)); 能够得到 文本信息吗??
    如果方便,请贴出来, (我这里的mysql图形工具不能得到完整信息,只能得到一行单个字段resutl的空值)
      

  9.   


    =====================================
    090729 13:49:19 INNODB MONITOR OUTPUT
    =====================================
    Per second averages calculated from the last 38 seconds
    ----------
    SEMAPHORES
    ----------
    OS WAIT ARRAY INFO: reservation count 13, signal count 13
    Mutex spin waits 2, rounds 20, OS waits 1
    RW-shared spins 24, OS waits 12; RW-excl spins 0, OS waits 0
    ------------
    TRANSACTIONS
    ------------
    Trx id counter 0 752628
    Purge done for trx's n:o < 0 750240 undo n:o < 0 0
    History list length 7
    Total number of lock structs in row lock hash table 0
    LIST OF TRANSACTIONS FOR EACH SESSION:
    ---TRANSACTION 0 0, not started, OS thread id 3744
    MySQL thread id 21, query id 2167 localhost 127.0.0.1 root
    show innodb status
    ---TRANSACTION 0 0, not started, OS thread id 2080
    MySQL thread id 1, query id 13 localhost 127.0.0.1 lx
    --------
    FILE I/O
    --------
    I/O thread 0 state: wait Windows aio (insert buffer thread)
    I/O thread 1 state: wait Windows aio (log thread)
    I/O thread 2 state: wait Windows aio (read thread)
    I/O thread 3 state: wait Windows aio (write thread)
    Pending normal aio reads: 0, aio writes: 0,
     ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
    Pending flushes (fsync) log: 0; buffer pool: 0
    154 OS file reads, 48 OS file writes, 44 OS fsyncs
    0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
    -------------------------------------
    INSERT BUFFER AND ADAPTIVE HASH INDEX
    -------------------------------------
    Ibuf for space 0: size 1, free list len 0, seg size 2, is empty
    Ibuf for space 0: size 1, free list len 0, seg size 2,
    0 inserts, 0 merged recs, 0 merges
    Hash table size 195193, used cells 95, node heap has 1 buffer(s)
    0.00 hash searches/s, 0.00 non-hash searches/s
    ---
    LOG
    ---
    Log sequence number 0 3783537
    Log flushed up to   0 3783537
    Last checkpoint at  0 3783537
    0 pending log writes, 0 pending chkp writes
    29 log i/o's done, 0.00 log i/o's/second
    ----------------------
    BUFFER POOL AND MEMORY
    ----------------------
    Total memory allocated 57210192; in additional pool allocated 383872
    Buffer pool size   3008
    Free buffers       2908
    Database pages     99
    Modified db pages  0
    Pending reads 0
    Pending writes: LRU 0, flush list 0, single page 0
    Pages read 99, created 0, written 14
    0.00 reads/s, 0.00 creates/s, 0.00 writes/s
    No buffer pool page gets since the last printout
    --------------
    ROW OPERATIONS
    --------------
    0 queries inside InnoDB, 0 queries in queue
    1 read views open inside InnoDB
    Main thread id 992, state: waiting for server activity
    Number of rows inserted 20, updated 0, deleted 0, read 63327
    0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
    ----------------------------
    END OF INNODB MONITOR OUTPUT
    ============================
      

  10.   

    thank u
    这是最开头的一个要求。如果java web程序应用发生了bug,比如try  catch 抛出错误,
    我是否能够根据这个例外在执行楼上的代码 执行完后 退出 (逻辑上是否可行?)
      

  11.   

    这个没有相关经验。执行sql语句要确保有connection,如果bug产生后没有connection是没法得到show innode status 的信息的
      

  12.   


    現在執行樓上代碼
    我用的是最新的mysql-connector-java-5.1.5-bin.jar  
    程序前面改了 import java.sql.Connection;
    import java.sql.DriverManager; 
    import java.sql.ResultSet;
    import java.sql.Statement;保存沒有錯誤 。 運行提示錯誤:
    java virtual Machine Laouncher
    could not find the main calss.   program will exit.代碼就是樓上的哦---估計還是我這邊配置原因 , java不是很熟悉
    java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
    at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:54)
    Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 1 more
    Exception in thread "main"
      

  13.   

    我试过了,程序没有任何问题,你运行的方式可能不正确。
    你在eclipse中用右键点击JTreeDemo.java文件“选择运行”->"java 应用程序"的方式运行试试,没问题的