package com.user;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.*;
public class userBean {
private String userId;
private String userName;
private String password;
private String email;
private int count;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setUserId(String userId) {
this.userId = userId;
}
public void setPassword(String password) {
this.password = password;
}
public void setCount(int count) {
this.count = count;
}
public String getPassword() {
return password;
}
public String getUserId() {
return userId;
}
public String getUserName() {
return userName;
}
public int getCount() {
return count;
}
/**
* 获取连接
*/
private Connection conn = null;
private void getConnection() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
;
try {
conn = DriverManager.getConnection("jdbc
dbc:ues"
;
} catch (SQLException ex1) {
}
// Statement stmt;
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
/**
* 检查用户名是否可用的方法
* @return 用户的个数
*/
public void checkUserName() {
int i = 0;
this.getConnection();
String sql = "select count(*) from userreg where username='" +
this.userName + "'";
System.out.println(sql);
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
i = rs.getInt(1);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
this.setCount(i);
System.out.println("检查用户名:" + count);
// return count;
}
/**
* 添加用户的方法
* @return 用户插入的行数
*/
public void addUser() {
this.getConnection();
String sql = "insert into userreg (username,password,email) values('" +
this.userName + "','" + this.password + "','" + this.email +
"')";
System.out.println(sql);
try {
Statement stmt = conn.createStatement();
this.count = stmt.executeUpdate(sql);
} catch (SQLException ex) {
ex.printStackTrace();
}
System.out.println( this.count );
}
}
只是 添加用户的方法,用户插入的行数是-1,你们说会不会是myEclipse6.5没有安装好哦,我在其他机子上用5.5打开有是1,不知道为什么。