组合Java与SQL2005实现试题随即抽取
作者:bea
在线测试的网站,你不可能将每次回答的试题都是一样的。这时你就要随机分配试题。实现方法:先从题库中随机抽取十道题,然后将其保存在另一张表中并将其相应的题号变为一到十。便于接下来的其他操作。 以下是Java代码: import java.awt.BorderLayout; import java.util.*; import java.awt.event.*; import java.awt.Container; import java.awt.EventQueue;
在线测试的网站,你不可能将每次回答的试题都是一样的。这时你就要随机分配试题。实现方法:先从题库中随机抽取十道题,然后将其保存在另一张表中并将其相应的题号变为一到十。便于接下来的其他操作。
以下是Java代码:
import java.awt.BorderLayout;
import java.util.*;
import java.awt.event.*;
import java.awt.Container;
import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Test extends JFrame {
public static final String DBDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public static final String DBURL="jdbc:sqlserver://localhost:1433;DatabaseName=SystemTest;SelectMethod=Cursor";
public static final String DBUSER="sa";
public static final String DBPASSWORD="123";
public static Connection conn=null;
public static Statement stmt=null;
public static Statement stmt1=null;
public static Statement stmt2=null;
public static ResultSet rs=null;
public static ResultSet rs1=null;
public static void main(String args[]) {
try{
//数据库的连接。
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
stmt= conn.createStatement(ResultSet. TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt1= conn.createStatement(ResultSet. TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt2= conn.createStatement(ResultSet. TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
}catch(Exception e)
{
e.printStackTrace();
}
Test t1=new Test();
t1.sel_save();
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test frame = new Test();
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
/*try{
sql_1="delete from stu_selAns";
stmt=conn.createStatement();
rs=stmt.executeQuery(sql_1);
}
catch(Exception event)
{
}*/
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame
*/
public Test() {
super();
setBounds(100, 100, 500, 386);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("测试");
final Container container = new Container();
container.setLayout(null);
getContentPane().add(container, BorderLayout.CENTER);
label = new JLabel();
label.setBounds(22, 68, 462, 57);
container.add(label);
final JButton nextButton = new JButton();
nextButton.setText("next");
nextButton.setBounds(60, 270, 106, 28);
container.add(nextButton);
nextButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{
int current=Integer.parseInt(label_3.getText());
current+=1;
if(current>0 &¤t 有用 | 无用
以下是Java代码:
import java.awt.BorderLayout;
import java.util.*;
import java.awt.event.*;
import java.awt.Container;
import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Test extends JFrame {
public static final String DBDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public static final String DBURL="jdbc:sqlserver://localhost:1433;DatabaseName=SystemTest;SelectMethod=Cursor";
public static final String DBUSER="sa";
public static final String DBPASSWORD="123";
public static Connection conn=null;
public static Statement stmt=null;
public static Statement stmt1=null;
public static Statement stmt2=null;
public static ResultSet rs=null;
public static ResultSet rs1=null;
public static void main(String args[]) {
try{
//数据库的连接。
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
stmt= conn.createStatement(ResultSet. TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt1= conn.createStatement(ResultSet. TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt2= conn.createStatement(ResultSet. TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
}catch(Exception e)
{
e.printStackTrace();
}
Test t1=new Test();
t1.sel_save();
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test frame = new Test();
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
/*try{
sql_1="delete from stu_selAns";
stmt=conn.createStatement();
rs=stmt.executeQuery(sql_1);
}
catch(Exception event)
{
}*/
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame
*/
public Test() {
super();
setBounds(100, 100, 500, 386);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("测试");
final Container container = new Container();
container.setLayout(null);
getContentPane().add(container, BorderLayout.CENTER);
label = new JLabel();
label.setBounds(22, 68, 462, 57);
container.add(label);
final JButton nextButton = new JButton();
nextButton.setText("next");
nextButton.setBounds(60, 270, 106, 28);
container.add(nextButton);
nextButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{
int current=Integer.parseInt(label_3.getText());
current+=1;
if(current>0 &¤t 有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- PHP面向对象编程快速了解
- 了解PHP开发网站的全过程
- PHP生成静态HTML页面原理与实例
- PHP在web开发中的优势在哪里
- PHP技巧:教你怎样过滤危险的HTML代码
- 浅谈PHP中MVC编程思想
- CSDN张孝祥老师辞世 老师一路走好
- 程序员工作经验总结 帮助你明白一些道理
- 中国互联网的未来主流:博客和论坛
- 程序员伤不起 说说程序员的生活
- 保存用户上次登录时间之JSP编程入门
- Java对上传图片进行等比例缩放等处理
- Java如何使用jdbc连接oracle数据库
- 编程入门之如何成为一名优秀的程序员
- Java编程入门之final的用法
- 下列程序员的9大坏习惯你占了几个
- Java常见的异常和解决的办法
- Java程序员面试题考考你知道多少
- 收集Java程序员值得去看的好书推荐