athen
发贴: 14
|
于 2005-04-18 23:21
发错了 一段代码 package cart; import java.sql.*; import java.util.*; import java.math.*; import java.lang.*; import com.microsoft.jdbc.sqlserver.*;
public class UserEntity { private String id; private String username; private String userpassword; public static String Str="com.microsoft.jdbc.sqlserver.SQLServerDriver"; public static String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tzj"; public static Connection conn=null; public UserEntity(String id,String username,String userpassword) {
try{ Class.forName(Str); }catch(java.lang.ClassNotFoundException e){e.getMessage();}
this.id=id; this.username=username; this.userpassword=userpassword; } public static UserEntity queryUser(String username) throws SQLException{ try{ Class.forName(Str); }catch(java.lang.ClassNotFoundException e){e.getMessage();} String sql="select user_id,user_name,user_password from user where user_password=?"; ResultSet rs=null; try{
conn=DriverManager.getConnection(url); PreparedStatement prepStmt=conn.prepareStatement(sql); prepStmt.setString(1,username); rs=prepStmt.executeQuery(); }catch(SQLException e){e.getMessage();}
UserEntity user=null; if(rs.next())
user=new UserEntity(rs.getString(1),rs.getString(2),rs.getString(3)); return user;
} public String getUserPassword(){
return userpassword; } public String getUserName(){ return username; } }
|