简体   繁体   English

如何将cmd中的命令输出到文本区域

[英]how to get output of a command in cmd into a text area

I am using Java and using Scanner class. 我正在使用Java并使用Scanner类。 I'll take an SQL query as input and store it into String s . 我将一个SQL查询作为输入并将其存储到String s

Scanner sc=new Scanner(System.in);
String s=sc.nextLine();

I want to execute this string (query) and display the result obtained in SQL command line in a text area in swings. 我想执行此字符串(查询),并在SQL命令行中的文本区域中摆动显示显示的结果。

For example if the input is 例如,如果输入是

update emp set no=526 where id='abc'

then the text area should display: 然后文本区域应显示:

1 row(s) updated 已更新1行

and similarly whatever is displayed in the SQL command line for any query. 以及类似的任何查询在SQL命令行中显示的内容。

BASICALLY OUTPUT OF COMMAND LINE SHOULD BE REDIRECTED TO TEXT AREA 命令行的基本输出应重定向到文本区域

If you are using JDBC to access the DB, you could do something like this: 如果使用JDBC访问数据库,则可以执行以下操作:

// Create the UPDATE statement
PreparedStatement pstmt = con.prepareStatement("update emp set no=? where id=?");
pstmt.setLong(1, 526L);
pstmt.setString(2, "abc");

// Execute it
int rowCount = pstmt.executeUpdate();
// You receive as result the count of modified rows
...
// And then update the textArea
textArea.setText(String.format("%d row(s) updated", rowCount));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM