为什么我运行完下面的程序后,它不能把我输入的uid,pwd之类的值存入数据库,却将uid,pwd这个字符串存入数据库了呢?请指教。
package DataBase;
import java.sql.*;
public class RegBean {
private Statement stmt = null;
ResultSet rs = null;
private Connection conn = null;
boolean flag=false;
String uid,pwd,career,nickname,name,gender,address,tel,year,month,date,email,birth;
String sql;
public RegBean() {
}
public void OpenConn(String dsn, String uid, String pwd) throws Exception {
try {
dsn = "jdbc:odbc:" + dsn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(dsn, uid, pwd);
}
catch (Exception ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
}
public void setuid(String uid)
{
this.uid=uid;
}
public void setpwd(String pwd)
{
this.pwd=pwd;
}
public void setnickname(String nickname)
{
this.nickname=nickname;
}
public void setname(String name)
{
this.name=name;
}
public void setgender(String gender)
{
this.gender=gender;
}
public void setcareer(String career)
{
this.career=career;
}
public void setaddress(String address)
{
this.address=address;
}
public void setemail(String email)
{
this.email=email;
}
public void settel(String tel)
{
this.tel=tel;
}
public void setyear(String year)
{
this.year=year;
}
public void setmonth(String month)
{
this.month=month;
}
public void setdate(String date)
{
this.date=date;
}
public boolean executeQuery(String sql) {
rs = null;
try {
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql="select * from custom where uid='"+uid+"'";
rs = stmt.executeQuery(sql);
if(rs.next())
flag=true;
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return flag ;
}
public void executUpdate(){
try{
birth=year+"-"+month+"-"+date;
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql=new String("insert into custom(uid,pwd,career,nickname,name,email,tel,address,gender,birth)") ;
sql=sql+"values('"+uid+"','"+pwd+"','"+career+"','"+nickname+"','"+name+"','"+email+"','"+tel+"','"+address+"','"+gender+"','"+birth+"')" ;
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeUpdate: " + ex.getMessage());
}
}
public void closeStmt(){
try{
stmt.close();
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
}
public void closeConn(){
try{
conn.close();
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
}
}