返回信息流求java高手帮改java程序,有人现在在吗?
这是一条镜像帖。来源:北邮人论坛 / java / #22685同步于 2012/6/6
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
求java高手帮改java程序
wzywkl
2012/6/6镜像同步19 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
public class Exam {
private int no;
private String answer;
private String question;
public void setno(int a){
this.no = no;
}
public void setanswer(String a){
this.answer = answer;
}
public void setquestion(String a){
this.question =question;
}
public int getno(){
return no;
}
public String getanswer(){
return answer;
}
public String getquestion(){
return question;
}
}
import java.awt.*;
import java.awt.event.*;
import java.security.interfaces.RSAKey;
import javax.swing.*;
public class Gui extends Frame {
TextField writeanswer;
Button b1, b2, b3;
Panel p1,p2,p3;
TextArea ta;
Sql sql = new Sql();
Gui() {
//监听器
Monitor1 m1 = new Monitor1();
Monitor2 m2 = new Monitor2();
Monitor3 m3 = new Monitor3();
//按钮设置
b1 = new Button("下一题");
b1.addActionListener(m1);
b2 = new Button("计分");
b2.addActionListener(m2);
b3 = new Button("退出");
b3.addActionListener(m3);
//布局设置
p1 = new Panel(new FlowLayout());
p2 = new Panel(new GridLayout(2, 1));
ta = new TextArea();
writeanswer = new TextField();
Label tihao = new Label(sql.question[2]);
add(p1);
p2.add(tihao);
p2.add(ta);
p1.add(p2);
p1.add(writeanswer);
p1.add(b1);
p1.add(b2);
p1.add(b3);
pack();
setVisible(true);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.interfaces.RSAKey;
import javax.swing.text.TabableView;
public class Monitor1 implements ActionListener {
public void actionPerformed(ActionEvent e1) {
try {
Sql sql = new Sql();
Gui gui = new Gui();
while(sql.rs.next()){
int no=sql.rs.getInt("no");
String question =sql. rs.getString("question");
String answer = sql.rs.getString("answer");
gui.ta.setText(question);
}
boolean endsignal = sql.rs.next();
if (endsignal = false)
System.out.print("答题结束");
}
catch (Exception e2) {
}
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Monitor2 implements ActionListener {
int record1 = 0;
String record = String.valueOf(record1);
public void actionPerformed(ActionEvent e) {
try {
Gui gui = new Gui();
Sql sql = new Sql();
String writeanswer = gui.writeanswer.getText();
if (writeanswer.equals(sql.rs.getString("answer"))) {
record1 = record1 + 10;
} else {
System.out.print("false");
}
} catch (Exception e3) {
}
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Monitor3 implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
import java.sql.*;
public class Sql {
Connection con;
Statement sql;
ResultSet rs;
int no[] = new int[10];
String question[] = new String[10];
String answer[] = new String[10];
Object[] ex=new Object[999];
int i = 0;
public Sql() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
System.out.print(e);
}
try {
con = DriverManager.getConnection("jdbc:odbc:MyData", "", "");
sql = con.createStatement();
rs = sql.executeQuery("select*from table");
System.out.print(rs.getInt("no"));
} catch (SQLException e) {
}
}
}
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
public class Test {
public static void main(String[] args) {
Gui gui = new Gui();
Sql sql = new Sql();
}
}
是做和数据库相连的单选题系统,单选题只有十题,但是不知道哪出了问题,题目无法显示到TextArea里面
【 在 mojia 的大作中提到: 】
: 贴上来吧
附件(512B) test.ldb
附件(356KB) test.mdb
【 在 wzywkl 的大作中提到: 】
: 求java高手帮改java程序,有人现在在吗?
是不是sql语法错了,select和*和from之间没空格?
rs = sql.executeQuery("select*from table");
不是那个原因,我改后运行了,还是不行
【 在 cthch 的大作中提到: 】
:
: 是不是sql语法错了,select和*和from之间没空格?
: rs = sql.executeQuery("select*from table");
好像数据库链接有问题,但是不晓得是哪里出错了,system.out 没结果显示
【 在 a328240784 的大作中提到: 】
: 你确定连接上数据库了?获取的数据打印出来了吗?system.out一下