sql语句的insert问题

mrying 2010-10-16 08:07:40
private String time1;
private String content1;
private int post1;
private int user;

...........
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=bbs","cq","123");
stmt=con.createStatement();
String sql="insert into Reply(content,time,userId,postId) values('"+content1+"','"+time1+"',post1,user)";
stmt.execute(sql);

报错:
在此上下文中不允许使用名称 "post1"。有效表达式包括常量、常量表达式和变量(在某些上下文中)。不允许使用列名。

它不允许使用post1,我就改了数十种名字,都是不允许使用 不知道出什么问题了
...全文
102 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
billpu 2010-10-16
  • 打赏
  • 举报
回复
四眼兄视力度数比较高 呵呵 看出来了
「已注销」 2010-10-16
  • 打赏
  • 举报
回复
4#多了两个单引号哦,呵呵~~
String sql="insert into Reply(content,time,userId,postId)
values('"+content1+"','"+time1+"',"+ post1 +"," +USER +")";
「已注销」 2010-10-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sqlcenter 的回复:]

#1 √
#4 ×
[/Quote]
SQLCenter 2010-10-16
  • 打赏
  • 举报
回复
#5 ×

#1 ×
#2
#4 ×
SQLCenter 2010-10-16
  • 打赏
  • 举报
回复
#1
#4 ×
「已注销」 2010-10-16
  • 打赏
  • 举报
回复
String sql="insert into Reply(content,time,userId,postId)
values('"+content1+"','"+time1+"',"+ post1 +"," +USER +"')'";
打一壶酱油 2010-10-16
  • 打赏
  • 举报
回复
就二楼那样吧
-狙击手- 2010-10-16
  • 打赏
  • 举报
回复
String sql="insert into Reply(content,time,userId,postId) values('"+content1+"','"+time1+"','post1','user')";


String sql="insert into Reply(content,time,userId,postId) values('"+content1+"','"+time1+"','"+post1+"','"+user+"')";
dawugui 2010-10-16
  • 打赏
  • 举报
回复
什么语言?看不懂呢?帮顶.

建议去java版问问.

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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