package jjj;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Random;
import java.sql.*;
import java.applet.Applet;
public class Wang extends Applet implements ActionListener{
static final String J="com.microsoft.jdbc.sqlserver.SQLServerDriver";
static final String Url="jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=wang85";
String sqls=null;
String i=suijishu();
Label p1=new Label("输入用户名:");
TextField test1=new TextField(5);
Label pp2=new Label("密码:");
TextField test2=new TextField(5);
Label pp=new Label("输入验证码:");
TextField test=new TextField(5);
Label pq=new Label(i);
JButton qq=new JButton("确定");
public void init(){
add(p1);
add(test1);
add(pp2);
add(test2);
add(pp);
add(test);
add(pq);
add(qq);
qq.addActionListener(this);
repaint();
}
public void paint(Graphics g)
{
}
public void actionPerformed(ActionEvent e) {
if(pq.getText()==i){
System.out.println("验证吗正确,请连接数据库");
shujuku();
System.out.println("chenggong");
}
else
System.out.println("验证吗错误,请重新输入");
}
public String suijishu(){
Random r = new Random();
String ww=new String();
String s=new String();int i=0;
while(i<4)
{ switch(r.nextInt(16))
{
case(0):s="0";break;
case(1):s="1";break;
case(2):s="2";break;
case(3):s="3";break;
case(4):s="4";break;
case(5):s="5";break;
case(6):s="6";break;
case(7):s="7";break;
case(8):s="8";break;
case(9):s="9";break;
case(10):s="a";break;
case(11):s="b";break;
case(12):s="c";break;
case(13):s="d";break;
case(14):s="e";break;
case(15):s="f";break;
case(16):s="g";break;
}
ww+=s;i++;
}
System.out.println(ww);
return ww;
}
public void shujuku(){
try{
Class.forName(J);
String login="sa";
String password="850207";
System.out.println("lianjie chenggong3");
Connection conn=DriverManager.getConnection(Url,login,password);
System.out.println("lianjie chenggong4");
Statement aa=conn.createStatement();
String sqlQery="select * from sc where score>60";
System.out.println("lianjie chenggong5");
ResultSet rs=aa.executeQuery(sqlQery); //为什么到这一句就不执行呀 ?
System.out.println("lianjie chenggong6");
while(rs.next()){
System.out.println(rs.getString(1)+",");
System.out.println(rs.getString(2)+",");
System.out.println(rs.getString(3)+",");
System.out.println("lianjie chenggong7");
}
aa.close();
conn.close();
}
catch(SQLException e)
{
}
catch(ClassNotFoundException e)
{
}
}
}
结果:
验证吗正确,请连接数据库
lianjie chenggong3
lianjie chenggong4
lianjie chenggong5
chenggong
------解决方案--------------------