Driver does not support this function

mohugomohu 2008-07-01 10:54:58
我用PreparedStatement,操作数据库,但出现
java.sql.SQLException: Driver does not support this function
为什么啊?
			String sql = "insert into Customer(phoneNum,name,sex,companyId,address,email)";
sql += " values(?,?,?,?,?,?)";
System.out.print(sql);
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.setString(1, phoneNum);
psmt.setString(2, name);
psmt.setString(3, sex);
psmt.setInt(4, companyId);
psmt.setString(5, address);
psmt.setString(6, email);
int count = psmt.executeUpdate(sql);
...全文
560 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
awusoft 2008-07-01
  • 打赏
  • 举报
回复
呵呵......
mohugomohu 2008-07-01
  • 打赏
  • 举报
回复
看来大家还是要练练眼力啊,
PreparedStatement psmt = conn.prepareStatement(sql);
这里已经将sql语句传进去了。
int count = psmt.executeUpdate(sql);
这里又传了sql语句进去,肯定错啊哈哈!
  • 打赏
  • 举报
回复
String sql = "insert into Customer(phoneNum,name,sex,companyId,address,email)";
sql += " values(?,?,?,?,?,?)";




语法就错了





mohugomohu 2008-07-01
  • 打赏
  • 举报
回复
我原来是用Statement直接拼凑sql语句,没有任何问题。
现在用PreparedStatement,不知道为什么不行了。
String sql = "insert into Customer(phoneNum,name,sex,companyId,address,email)";
sql += " values(?,?,?,?,?,?)";
values都是问号,怎么能直接在数据库运行啊!
lisl2003 2008-07-01
  • 打赏
  • 举报
回复
能不能先尝试直接在数据库上执行你的sql语句试试?
mohugomohu 2008-07-01
  • 打赏
  • 举报
回复
	public String insertCustomer(CustomerObj customer) {// 添加客户
Connection conn = null;
String msg = "";
try {
conn = ConnectionUtil.getConnection();
// 获取将添加的客户信息
String phoneNum = customer.getPhoneNum();
String name = customer.getName();
String sex = customer.getSex();
int companyId = customer.getCompanyId();
String address = customer.getAddress();
String email = customer.getEmail();
String sql = "insert into Customer(phoneNum,name,sex,companyId,address,email)";
sql += " values(?,?,?,?,?,?)";
System.out.print(sql);
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.setString(1, phoneNum);
psmt.setString(2, name);
psmt.setString(3, sex);
psmt.setInt(4, companyId);
psmt.setString(5, address);
psmt.setString(6, email);
int count = psmt.executeUpdate(sql);
if (count > 0) {
msg = "添加成功!";
} else {
msg = "添加失败!";
}
} catch (Exception ex) {
System.out.print(ex.toString());
msg = "系统发生错误!";
} finally {
ConnectionUtil.closeConnection(conn);
}
return msg;
}
zhj92lxs 2008-07-01
  • 打赏
  • 举报
回复
sql没错,怪
mjgwf 2008-07-01
  • 打赏
  • 举报
回复
很厉害,值得学习,呵呵!
liuyangccu 2008-07-01
  • 打赏
  • 举报
回复
学习中...
lisl2003 2008-07-01
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zzkk_1980 的回复:]
眼拙了
[/Quote]
zidasine 2008-07-01
  • 打赏
  • 举报
回复
还是楼主眼力好啊
zzkk_1980 2008-07-01
  • 打赏
  • 举报
回复
眼拙了

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧