怎么用java程序来执行jdb 命令呢

怎么用java程序来执行jdb 命令呢

试试这个,在java.lang.Runtime中有很多方法可用的,你看看。
[code="java"]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class TestRuntime
{
private static final String[] CMD_ITEMS = {"javac -g HelloWord.java", "jdb HelloWord", "stop at HelloWord:4", "run"};

public static void main(String[] args)
{
    Process process = null;
    try
    {
        for (String cmd : CMD_ITEMS)
        {
            System.out.println("命令 >>>>>> " + cmd);
            process = Runtime.getRuntime().exec(cmd);
            //执行命令      
            //取得命令结果的输出流      
            InputStream fis = process.getInputStream();
            //用一个读输出流类去读      
            InputStreamReader isr = new InputStreamReader(fis);
            //用缓冲器读行      
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            //直到读完为止      
            while ((line = br.readLine()) != null)
            {
                System.out.println(line);
            }
        }

    }
    catch (IOException e)
    {
        System.out.println(e.getLocalizedMessage());
    }
}

}

[/code]

[code="java"]Class.forName("Driver");
Connection conn=DriverManager.getConnection("url","name","password");
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
[/code]

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Test {

public static void main(String[] args) throws Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    PreparedStatement stmt = null;
    String sql1 = "select * from 表名";
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@IP地址:1521:SID", "用户名", "口令");
    stmt = conn.prepareStatement(sql1);
    ResultSet rs = stmt.executeQuery();
}

}
Oracle数据库的访问示例。网上这种例子一抓一大把。另外,你问的是JDBC吧?

package com.yymt.pf.rpc.loadbalance;

import java.io.File;

import java.io.IOException;

public class ExecFileUtil {

public static void main(String[] args) throws IOException {

run("cmd /C start startup.bat", null, new File(

"E:\develop_tools\apache-tomcat-6.0.26\bin\"));

System.out.println("Started!");

}

/**

* @param path

* a specified system command

* @param envp

* array of strings, each element of which has environment

* variable settings in the format name=value, or null if the

* subprocess should inherit the environment of the current

* process.

* @param dir

* the working directory of the subprocess, or null if the

* subprocess should inherit the working directory of the current

* process.

* @return

* @throws IOException

*/

public static Process run(String cmd, String[] envp, File dir)

throws IOException {

Runtime rt = Runtime.getRuntime();

return rt.exec(cmd, envp, dir);

}

}

可以使用以下方法:
[code="java"]
private final String CMD_JDB="JDB";
Runtime.getRuntime().exec(CMD_JDB);
[/code]
不知道是不是你需要的结果。

public class BaseDao {
private static SqlMapClient sqlMapper;
public static synchronized SqlMapClient getSqlmap() {
if (sqlMapper == null) {
try {
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sqlMapper;
}

}

connection.properties

jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@10.6.78.244:1521:denali

jdbc.username=scmdp

jdbc.password=scmdp

如下,将CMD替换成你的命令就可以了。
[code="java"]
package com.chinasoft.demo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class TestRuntime
{
private static final String CMD = "ipconfig -all";

public static void main(String[] args)
{
    Process process = null;
    try
    {
        process = Runtime.getRuntime().exec(CMD);
        //执行命令   
        //取得命令结果的输出流   
        InputStream fis = process.getInputStream();
        //用一个读输出流类去读   
        InputStreamReader isr = new InputStreamReader(fis);
        //用缓冲器读行   
        BufferedReader br = new BufferedReader(isr);
        String line = null;
        //直到读完为止   
        while ((line = br.readLine()) != null)
        {
            System.out.println(line);
        }

    }
    catch (IOException e)
    {
        System.out.println(e.getLocalizedMessage());
    }
}

}

[/code]