当前位置: 编程技术>java/j2ee
java+sql2005 随机抽取试题的代码
来源: 互联网 发布时间:2014-10-18
本文导语: 代码如下: 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...
代码如下:
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