当我试图运行我的gui将数据插入到表中时,我收到错误,错误是无法使用executeQuery()发出数据操作语句。这个gui的目标是让用户在文本区域输入信息,然后单击“提交”,这些信息将上传到数据库。
错误:java.sql.SQLException:无法使用executeQuery()发出数据操作语句。
答案 0 :(得分:1)
您必须使用此方法PreparedStatement#executeUpdate()代替executeQuery
在此PreparedStatement对象中执行SQL语句 必须是SQL数据操作语言(DML)语句,例如 INSERT,UPDATE或DELETE;或者什么都不返回的SQL语句, 例如DDL声明。
答案 1 :(得分:0)
当我试图从下面的代码中删除记录时,我遇到了同样的问题
@Repository
@Transactional
public interface IAeqplUserStagePermissionRepository extends JpaRepository<AeqplUserStagePermissionEntity, Long> {
@Query(value = "DELETE FROM aeqpl_user_stage_permissions WHERE aeqpluser_id = :aeqpluserId",nativeQuery = true)
int deleteByUserId(Long aeqpluserId);
}
解决方案:使用@Modifying
@Modifying
@Query(value = "DELETE FROM aeqpl_user_stage_permissions WHERE aeqpluser_id = :aeqpluserId",nativeQuery = true)
int deleteByUserId(@Param("aeqpluserId")Long aeqpluserId);