java sql 类_Java sql用户类

Possible Duplicate:

Java user class

看看我的代码。哪里不对?输出是“找不到用户”。

package it.unitn.ing.guide;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.ArrayList;

public class LoginDao {

private static Statement stm = null;

private static ResultSet rs = null;

private static Connection con = null;

private static int i;

private it.unitn.ing.guide.User user;

private User user_set;

public User authenctication(String eMail, String password, int i) {

try {

ArrayList user_set = new ArrayList();

con = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "root");

stm = con.createStatement();

rs = stm.executeQuery("SELECT * FROM User,Role WHERE (user.id=role.id) AND (user.email='" + eMail + "')");

while (rs.next()) {

while (rs.next()) {

User user = new User();

user.setAddress(rs.getString(""));

user.setCountry(rs.getString(""));

user.setCreatedBy(rs.getString(""));

user.setEMail(rs.getString(""));

user.setId(rs.getInt(""));

user.setIsLocked(rs.getString(""));

user.setLastLoginDate(rs.getDate(""));

user.setName(rs.getString(""));

user.setPassword(rs.getString(""));

user.setPasswordFormat(rs.getString(""));

user.setPasswordFormat(rs.getString(""));

user.setPasswordSalt(rs.getString(""));

user.setPhoneNumber(rs.getInt(""));

user.setPhoneNumberNull(rs.getBoolean(""));

user.setRegistrationDate(rs.getDate(""));

user.setRoleId(rs.getInt(""));

user.setUserName(rs.getString(""));

user_set.add(user);

}

}

} catch (Exception sqlEx) {

System.out.println("sqlexecuteException: " + sqlEx.toString());

}

return user_set;

}

public static void main(String[] args) throws Exception {

LoginDao loginDao = new LoginDao();

User user = loginDao.authenctication("rashed", "rashed", i);

if (user != null) {

System.out.println(user.getId());

} else {

System.out.println("No user Found");

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值