【发布时间】:2015-08-07 08:29:13
【问题描述】:
正在开发一个应用程序来查询表并在 JTextarea 中将其打印出来,但没有响应而是标记错误“非法开始表达式”请是新手,我需要帮助,这是我的代码,谢谢
try{
//get connection to the database
Connection myconn=DriverManager.getConnection("jdbc:mysql://localhost:3306/cbt_for_java", "root","");
//create a statement
Statement mystmt=myconn.createStatement();
//execute sql query
ResultSet myrs = mystmt.executeQuery("select * from jamb WHERE ID = '1'");
//process the result set
// System.out.println(myrs.getString("ID") + "." + myrs.getString("question"));
}
catch(Exception exc){
exc.printStackTrace();
}
BorderLayout questionareaLayout = new BorderLayout();
JPanel questionp = new JPanel();
JTextArea question=new
//this is where the problem is
JTextArea(System.out.println(myrs.getString("ID") + "." + myrs.getString("question"));,22,111);
question.setEditable(false);
questionp.add(question);
add(questionp);
【问题讨论】:
-
你可能想使用
setText()或直接使用JtextArea("this is the text");而不使用system.out.println() -
请人帮忙
-
嗯,@UmaKanth 确实有帮助。
-
System.out.println()用于在标准输出上打印字符串,它不返回任何内容。 -
要更改
JTextArea的内容,请使用setText()或append()。但是,如果你真的想要,你可以将System.out重定向到JTextArea:stackoverflow.com/questions/14706674/…