Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
Ron McLeod
Junilu Lacar
Liutauras Vilda
Sheriffs:
Paul Clapham
Jeanne Boyarsky
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Piet Souris
Carey Brown
Bartenders:
Jesse Duncan
Frits Walraven
Mikalai Zaikin
Forum:
JDBC and Relational Databases
delete row from database
maggie karve
Ranch Hand
Posts: 187
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi...
I am trying to delete a row from the database...but the query is not getting executed and i am getting exception
package myServlets; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.util.*; public class Delete extends HttpServlet{ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException { String billDate=request.getParameter("Date"); System.out.println(billDate); String url = "jdbc:postgresql://localhost/Books"; Connection con=null; ResultSet rs; String s; Statement st=null; PreparedStatement pstmt = null; String sqlstr ="DELETE FROM \"BookSchema\".\"Bill\" WHERE \"BillMonthYear\"=?"; try { st = con.createStatement(); rs = st.executeQuery(sqlstr); pstmt = con.prepareStatement(sqlstr); pstmt.setString(1,billDate); pstmt.executeUpdate(); } catch(Exception er) { er.printStackTrace(); } finally { if (pstmt!=null) try { pstmt.close(); } catch(SQLException sq) { sq.printStackTrace(); } if (con!=null) try { con.close(); } catch(SQLException sql) { sql.printStackTrace(); } } } public void doGet(HttpServletRequest request, HttpServletResponse response) { System.out.println("in doGetmethod"); try { doPost(request,response); } catch(Exception ae) { ae.printStackTrace(); } } }
the exception i am getting is
org.postgresql.util.PSQLException: ERROR: syntax error at end of input Position: 58 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryEx ecutorImpl.java:2062) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutor Impl.java:1795) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.ja va:257) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Stat ement.java:479) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(Abstract Jdbc2Statement.java:353) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdb c2Statement.java:299) at myServlets.Delete1.doPost(Delete1.java:25) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV alve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV alve.java:191) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica torBase.java:465) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j ava:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j ava:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal ve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav a:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java :852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce ss(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:48 9) at java.lang.Thread.run(Unknown Source)
maggie karve
Ranch Hand
Posts: 187
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i added con value and removed ResultSet .
and i am able to delete a particular row now..
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
passing many values from jsp and getting only one value in servlet?
Servlet Chaining
update query
SQLException:Parameter Index out of Range
exception while running code
More...