java中的Mysql语句没有执行 [英] Mysql statement in java not executing

查看:22
本文介绍了java中的Mysql语句没有执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Java 中有一个函数,用于更新 mysql 数据库中表的描述字段和标题字段,如下所示:

I have a function in Java that is meant to update the description field and the title field of a table in a mysql database that looks like this:

public void updateDescription( String desc, String title, int urlid ) throws SQLException, IOException {
    String cutDesc = desc.substring(0, 99);
    Statement stat = connection.createStatement();
    String query = "UPDATE urls SET description = '"+cutDesc+"', title = '"+title+"' WHERE urlid =" + urlid;
    stat.executeUpdate( query );
    stat.close();
}

当这个函数被调用时:

updateDescription(desc, title, urlID);

什么都没有放在桌子上.没有错误,它似乎只是忽略了它.知道这里有什么问题吗?

Nothing is put into the table. There are no errors, it just seems to ignore it. Any ideas what is wrong here?

谢谢

推荐答案

你说什么都没有放入表中.

You said nothing is put into the table.

但是 UPDATE 不会将内容放入表中 - 它只会修改已经存在的行.您需要使用 INSERT 而不是 UPDATE.

But UPDATE doesn't put things into the table - it only modifies rows that already exist. You need to use INSERT instead of UPDATE.

这篇关于java中的Mysql语句没有执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆