更改表外键从 java 到 mysql
好吧,我想对我的数据库进行修改,所以我需要使用 alter table,但 java 似乎在做这件事时遇到了问题。
这句话
ALTER TABLE loans ADD FOREIGN KEY (id_reader) REFERENCES readers (id);
你怎么执行呢?
我正在这样做:
rawStatement="ALTER TABLE loans ADD FOREIGN KEY (id_reader) REFERENCES readers (id);";
currentStatement = conn.createStatement();
currentStatement.execute(rawStatement);
最后一行正确吗?
据我所知,execute
必须运行所有内容。
Well, I want to make a modification in my database, so I need to use alter table but java seems to have problems making that.
This is the sentence
ALTER TABLE loans ADD FOREIGN KEY (id_reader) REFERENCES readers (id);
how do you execute it?
I was doing this:
rawStatement="ALTER TABLE loans ADD FOREIGN KEY (id_reader) REFERENCES readers (id);";
currentStatement = conn.createStatement();
currentStatement.execute(rawStatement);
is the last line correct?
As far I know, execute
must run everything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用这个< /a>:
而不是
Also if the Constraint is已经存在,它将抛出异常
您应该注意的其他事项:
Use this:
instead of
Also if the constraint is already present it will throw an exception
Other things you should look out for:
尝试使用下面的代码:
Try with the below code: