Statement statement = con.createStatement();
//insert语句
String savesql = "insert into sys_user values('" + name + "','"
+ passw + "')";
statement.execute(savesql);
//select语句
String sql = "select * from sys_user";
statement.executeQuery(sql);
注意:insert,update语句的时候,需要使用statement.execute(sql);若使用statement.executeQuery(sql);会报异常如下:
Can not issue data manipulation statements with executeQuery()
......
本文介绍了如何使用Java通过SQL语句进行数据库操作,包括插入(insert)和查询(select)的基本语法。特别指出,在执行插入或更新语句时,应使用statement.execute(sql),而非statement.executeQuery(sql),后者仅适用于查询语句。
759

被折叠的 条评论
为什么被折叠?



