我用的是JDBC链接的SQL SERVER2000
1。这是链接SQL SERVER2000的:
package atm;import java.sql.Connection;
import java.sql.DriverManager;public class Conn {
static Connection con ;
static{
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=pubs";
con = DriverManager.getConnection(url,"sa","");
}catch(Exception e){
e.printStackTrace();
}
}
public static Connection getconn(){
return con;
}
}2。这是用户信息
package atm;import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;//生成一个随即的10位数的卡号//
public class Users {
public static String reg(String name,String pwd,double money) throws Exception{
String uuid = UUID.randomUUID().toString().replaceAll("-","");
uuid = uuid.substring(0,10);
String tmpId = "";
for(int i=0;i<10;i++){
tmpId = tmpId+(int)uuid.charAt(i);
}
tmpId = tmpId.substring(0,10);
String sql ="insert into users values('"+tmpId+"','"+name+"','"+pwd+"',"+money+")";
Statement st = Conn.getconn().createStatement();
st.execute(sql);


uuid = UUID.randomUUID().toString().replaceAll("-","");
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dt = s.format(new Date());
sql = "insert into history values('"+uuid+"','"+tmpId+"','"+dt+"','开户',"+money+")";
st.execute(sql);
return tmpId;
}

// 卡号密码的验证项//
public static boolean login(String cid,String pwd) throws Exception{
String sql = "select count(*) from users where cid='"+cid+"' and pwd='"+pwd+"'";
Statement st = Conn.getconn().createStatement();
ResultSet rs = st.executeQuery(sql);
rs.next();
int a = rs.getInt(1);
if(a>0){
return true;

}else{
return false;
}
}
//存钱方法 //
public static void save(double money1)throws Exception{
         
                            ??????????????????
                
       }      
        }
3。这是主方法package atm;import java.util.Scanner;public class Main {
public static Scanner sc = new Scanner(System.in);
public Main() throws Exception{
while(true){
System.err.println("1: 注册");
System.err.println("2: 登录");
System.err.println("0: 退出");
String op = sc.next();
if(op.equals("1")){
reg();
}else if(op.equals("2")){
login();
}else if(op.equals("0")){
break;
}
}
}

//用户注册项//
public void reg() throws Exception{
System.err.println("请输入你的卡号:");
String name = sc.next();
System.err.println("请输入你的密码:");
String pwd = sc.next();
System.err.println("请输入你的初始金额:");
double money = sc.nextDouble();
String no = Users.reg(name, pwd, money);
System.err.println("你注册成功了,你的卡号是:"+no);

}


//用户登录项//
public void login() throws Exception{
System.err.println("请输入你的卡号:");
String name = sc.next();
System.err.println("请输入你的密码:");
String pwd = sc.next();
boolean b = Users.login(name, pwd);
System.err.println(b);
if(b==true){
operation();
}
}



//功能选择项//
    public static  void operation()throws Exception{
     while(true){
     System.err.println("1:存钱");
     System.err.println("2:取钱");
     System.err.println("3:查看交易记录");
     System.err.println("4:查看余额");
     System.err.println("5:修改密码");
     System.err.println("6:退出");
     String op=sc.next();
     if(op.equals("1")){
     save();
     }else if(op.equals("2")){
    
     }else if(op.equals("3")){
    
     }else if(op.equals("4")){
    
     }else if(op.equals("5")){
    
     }else if(op.equals("6")){
     System.exit(0);
     }
     }
    }
    //存钱 //
     public static void save(){
     System.err.println("请输入你要存的金额:");  
     double money1=sc.nextDouble();
     System.err.println("存款成功");
     } 
     
    //main方法//
public static void main(String[] args) throws Exception {
new Main();
}
}
4。这是SQL SERVER建的表
/*atm*/
create table users(
cid varchar(10) primary key,
name varchar(20),
pwd   varchar(20),
money numeric(10,2)
);
create table history(
id varchar(32) primary key,
cid varchar(10),
dt  varchar(19),/*2010-09-09 23:45:00*/
type varchar(2),
money numeric(10,2)
);