| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 449 人关注过本帖
标题:无法存入数据库
取消只看楼主 加入收藏
沙漠玫瑰
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-4-13
收藏
 问题点数:0 回复次数:0 
无法存入数据库

为什么我运行完下面的程序后,它不能把我输入的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());
}
}
}

搜索更多相关主题的帖子: 数据库 
2007-04-14 08:59
快速回复:无法存入数据库
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032965 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved