Can not issue data manipulation statements with executeQuery()

问题描述

各位技术牛人,请帮小弟解决一下这个问题CannotissuedatamanipulationstatementswithexecuteQuery()代码如下:publicUserselectUser(Stringusername){Connectionconn=null;PreparedStatementst=null;ResultSetrs=null;Useruser=null;try{Stringsql="select*fromuserwhereusername=?";user=newUser();conn=JdbcUtil.getConnection();st=conn.prepareStatement(sql);st.setString(1,username);rs=st.executeQuery();while(rs.next()){if(username.equals(rs.getString("username"))){user.setUsername(rs.getString("username"));user.setPassword(rs.getString("password"));user.setEmail(rs.getString("email"));user.setMajor(rs.getString("major"));user.setSex(rs.getString("sex"));user.setTruename(rs.getString("truename"));user.setPhoto(rs.getString("photo"));user.setView_photo(rs.getString("view_photo"));user.setTel(rs.getString("tel"));}}}catch(SQLExceptione){e.printStackTrace();}finally{JdbcUtil.close(rs);JdbcUtil.close(st);JdbcUtil.close(conn);}returnuser;}

解决方案

解决方案二:
不能执行query,原因:executeQuery()语句是用于产生单个结果集,而你返回的是多个结果集
解决方案三:
publicUserselectUser(Stringusername)你改为publicList<User>selectUser(Stringusername)然后再定义一个List集合:List<User>list=newArrayList<User>();并且在遍历结果集时,改为:if(username.equals(rs.getString("username"))){Useruser=newUser();user.setUsername(rs.getString("username"));user.setPassword(rs.getString("password"));user.setEmail(rs.getString("email"));user.setMajor(rs.getString("major"));user.setSex(rs.getString("sex"));user.setTruename(rs.getString("truename"));user.setPhoto(rs.getString("photo"));user.setView_photo(rs.getString("view_photo"));user.setTel(rs.getString("tel"));list.add(user);}最后returnlist;即可。。。
解决方案四:
我现在是想返回一个User不过很谢谢你!
解决方案五:
什么数据库?
解决方案六:
MySQL数据库
解决方案七:
看看数据库的驱动和数据库的版本最好一致

时间: 2024-09-23 19:50:35

Can not issue data manipulation statements with executeQuery()的相关文章

Data Manipulation with ADO.NET

ado Data Manipulation with ADO.NET

SQL jdbc解决自动自动增长列统一处理问题纪实

sql|解决|问题 sql server2005 jdbc解决自动自动增长列统一处理问题纪实 作者fbysssmsn:jameslastchina@hotmail.com  blog:blog.csdn.net/fbysss声明:本文由fbysss原创,转载请注明出处 关键字:自动增长列,jdbc,sqlserver2005 背景:系统要支持多种数据库,统一insert的时候获取自动增长列的处理方式问题1:insert+select方案sqlserver2000可以使用insertSql  +

sql server2005 jdbc解决自动增长列统一处理问题纪实

背景:系统要支持多种数据库,统一insert的时候获取自动增长列的处理方式 问题1:insert+select方案 sqlserver2000可以使用insertSql + SELECT @@IDENTITY AS 'Identity'的方式来获得,但是mysql则只能使用executeUpdate(insertSql); executeQuery('SELECT last_insert_id() ')这样的方式,否则会抛出异常:java.sql.SQLException: Can not is

struts2.0-Struts2 连接数据库 用list 进行用户注册

问题描述 Struts2 连接数据库 用list 进行用户注册 不知道哪里错了,该怎么改,求各位大神教!谢谢! 报错: Can not issue data manipulation statements with executeQuery(). 代码如下: public class person_entity_dao { public List quaryList(String name,String age,String sex,String time,String telphone,Str

MySQL · 特性分析 · InnoDB transaction history

1. 背景 在写压力负载比较重的MySQL实例上, InnoDB可能积累了较长的没有被purge掉的transaction history,导致实例性能的衰减,或者空闲空间被耗尽,下面就来看看它是怎么产生的,或者有没有什么方法来减轻,避免这样的问题出现. 2. InnoDB purge概要 InnoDB是一个事务引擎,实现了MVCC特性,也就是在存储引擎里对行数据保存了多个版本.在对行数据进行delete或者update更改时,行数据的前映像会保留一段时间,直到可以被删除的时候. 在大部分OLT

Leveraging IoT Data in the Cloud: Why Your Business is More at Risk than You Think

According to Gartner, 6.4billion "things" will be in use worldwide in 2016 and the technology consulting firm expects this number to grow to 21 billion by 2020. That's a massive amount of data and devices to manage and integrate into the cloud.

SQL Programming using .NET

SQL Programming using .NETSubmitted ByUser LevelDate of SubmissionTimothy VanoverIntermediate02/01/2001Download Project: StoredProcs.zip   192 KB The StoredProc.exe program can be used to show several different data objects, some draw backs of each a

【SQL】Using Oracle&#039;s Parallel Execution Features

The full list of Oracle parallel execution features currently includes the following Parallel Query Parallel DML Parallel DDL Parallel Data Loading Parallel Recovery Parallel Replication How Parallel Execution Works Operations That Can Be Parallelize

【OH】Glossary Oracle词汇表(中)

Glossary [OH]Glossary Oracle词汇表(中) Oracle? Database Net Services Administrator's Guide 11g Release 2 (11.2) E41945-02 Glossary ● access control list (ACL) The group of access directives that you define. The directives grant levels of access to specif