|
查看: 1508|回复: 7
|
请问关于JAVA用sql问题....
[复制链接]
|
|
|
我想问下,假如我有order table, item table, 和order_item table
order table有OrderID , item table有ItemID....
两个table的primary key 组合起来变成order_item table的composite key...
假如我有data要放进order_item table....
我需要用到 INSERT SQL, 各位高手可以教教我要怎样code sql 吗? 因为要consistence.
我之前的code是这样的
prepareStmtInsert = conShop.prepareStatement("INSERT INTO Order_Item VALUES(?,?,?,?,?) WHERE (OrderRecord.OrderID=Order_Item.OrderID AND Item.ItemID=Order_Item.ItemID);",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
不过我一直有invalid crusor state error
希望有高手可以指教指教,感激不尽~ |
|
|
|
|
|
|
|
|
|
|
发表于 23-11-2009 12:18 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 24-11-2009 07:16 PM
|
显示全部楼层
就是google了找不到才来这里
谢谢你的帮忙~  |
|
|
|
|
|
|
|
|
|
|
发表于 19-12-2009 07:17 PM
|
显示全部楼层
|
没看到你INNER JOIN 的,要不然用两次INSERT .... |
|
|
|
|
|
|
|
|
|
|
发表于 22-12-2009 06:04 PM
|
显示全部楼层
有
prepareStmtInsert.executeUpdate()?? |
|
|
|
|
|
|
|
|
|
|
发表于 23-12-2009 09:10 PM
|
显示全部楼层
我想问下,假如我有order table, item table, 和order_item table
order table有OrderID , item table有It ...
skydestiny3 发表于 22-11-2009 08:59 PM 
做么你insert data 要 用到 WHERE (OrderRecord.OrderID=Order_Item.OrderID AND Item.ItemID=Order_Item.ItemID)?
醬就可以了嗎“prepareStmtInsert = conShop.prepareStatement("INSERT INTO Order_Item VALUES(?,?,?,?,?) ” |
|
|
|
|
|
|
|
|
|
|
发表于 5-1-2010 12:08 PM
|
显示全部楼层
insert into order_item values (?,?,?,?) where exists (select * from order,item where order.orderID=$yourValue and item.itemID=$yourvalue)
Long time didnt touch sql , please run this query in your database before u put into ur java code else you will receive many error and find no where to debug
Have you run ur query in ur DB before you put it into your java code? |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-1-2010 01:49 PM
|
显示全部楼层
谢谢大家热心帮忙,我已解决了问题  |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|