JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 [問題]Can not issue data manipulation statements with executeQuery()
shinelove





發文: 6
積分: 0
於 2004-07-29 11:53 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
<%@ include file="global/mySQL.jsp" %>
<%
  try{
          rs=stmt.executeQuery("insert into `group`(group_id,group_name) values('1','God')");
  }catch(Exception e){out.println(e);}
%>
<%@ include file="global/mySQL_end.jsp" %>


錯誤訊息:java.sql.SQLException: Can not issue data manipulation statements with executeQuery()

用select查詢是沒有問題的,可是新增資料就會出現上面的錯誤訊息
新增語法若直接在mySQL使用也沒有問題(可以直接新增)
還是新手請多多指教,謝謝.......>_<
作業環境:win2000、j2sdk1.4.1_01、 MySQL 4.0.18-nt


shinelove edited on 2004-07-31 08:09
reply to postreply to post
作者 Re:[問題]java.sql.SQLException: Can not issue data manipulation statements with executeQuery() [Re:shinelove]
linexpmail

好玩就好



發文: 456
積分: 15
於 2004-07-29 12:28 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
參考看看
http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/statement.html#1003674

1
2
The method executeQuery is designed for statements that 
produce a single result set, such as SELECT statements.
1
2
3
The method executeUpdate is used to execute INSERT, UPDATE, 
or DELETE statements and also SQL DDL (Data Definition Language) 
statements like CREATE TABLE, DROP TABLE, and ALTER TABLE.... 


reply to postreply to post
不除妄想不求真
作者 Re:[問題]java.sql.SQLException: Can not issue data manipulation statements with executeQuery() [Re:shinelove]
shinelove





發文: 6
積分: 0
於 2004-07-29 14:56 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝linexpmail的回答~
我將程式改用Update後..卻出現另一個錯誤

錯誤訊息:
description: The server encountered an internal error () that prevented it from fulfilling this request.
incompatible types
found : int
required: java.sql.ResultSet
rs=stmt.executeUpdate("insert into `group`(group_id,group_name) values('1','God')");
        ^
麻煩大大們提示一下了...>_<


reply to postreply to post
作者 Re:[問題]java.sql.SQLException: Can not issue data manipulation statements with executeQuery() [Re:shinelove]
atriatri





發文: 110
積分: 0
於 2004-07-29 15:32 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
shinelove wrote:
謝謝linexpmail的回答~
我將程式改用Update後..卻出現另一個錯誤

錯誤訊息:
description: The server encountered an internal error () that prevented it from fulfilling this request.
incompatible types
found : int
required: java.sql.ResultSet
rs=stmt.executeUpdate("insert into `group`(group_id,group_name) values('1','God')");
        ^
麻煩大大們提示一下了...>_<

請注意 :
stmt.executeQuery 傳回 ResultSet
stmt.executeUpdate 傳回 int
所以你的程式當然會出現error


reply to postreply to post
作者 Re:[問題]java.sql.SQLException: Can not issue data manipulation statements with executeQuery() [Re:shinelove]
shinelove





發文: 6
積分: 0
於 2004-07-29 16:59 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝atriatri的提示~
之前用SQL2000不知為什麼用Query就可以新刪修了~
以致於我有了錯誤的觀念~
現在我的問題已經解決了~再次感謝


reply to postreply to post
作者 Re:[問題]java.sql.SQLException: Can not issue data manipulation statements with executeQuery() [Re:linexpmail]
yemen





發文: 2
積分: 0
於 2007-11-19 23:27 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
insert语句是用executeUpdate(sql)
而不是executeQuery().


reply to postreply to post
» JWorld@TW »  Servlet/JSP 討論區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8