java.insert,带SQL的JAVA:insert命令的返回值?
I have a table of authors : authorID, authorName.
authorID is a pk with auto increment.
I'd like to write a method in java that gets a name from user and adds it to the table. however i need to return the id of the author. is there a way to do that with 1 sql statement?
for example if my code has the command:
(1) is the author name.
Now if i write:
ResultSet rs =uteUpdate("INSERT INTO authors " + "VALUES (, '"+ (1) +"')");
write的返回值it says error as rs is resultset but the returned value is int. is this int the pk of the row that i have inserted?
解决⽅案
try
ResultSet rs = GeneratedKeys();
<();
long pk = rs.getLong(1);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论