Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple coding, still not working, may day!!!!

 
ramesh kumar
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI friends, below is one of my servlet coding.
please help me to odebug it. it has got as usual sql error, huhhhh.

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class Delete1 extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

String username = req.getParameter("name");
String address = req.getParameter("address");
PrintWriter pw=res.getWriter();
pw.println("Name "+username);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con= DriverManager.getConnection("jdbcdbc:ramesh","","");
if(con ==null){
pw.println("there is error in connection");}
else{pw.println("wawww there is connection");}

String stri= "delete members where name=?";
PreparedStatement pst=con.prepareStatement(stri);
pst.setString(1,username);
int records = pst.executeUpdate();

pw.println("your record has been deleted in the database");

pst.close();

}
catch(ClassNotFoundException e) {pw.println("there is error");}
catch(SQLException e){pw.println("oops, errorrrrr" +e.getMessage());}

}
}


The result I am getting is below

Name ramesh
wawww there is connection
oops, errorrrrr[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'members where name=Pa_RaM000'.

------------------
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String stri= "delete members where name=?";
PreparedStatement pst=con.prepareStatement(stri);

Your PreparedStatement is WRONG. I strongly suggest
that you first take the JDBC tutorial from Sun and then start your practice. The tutorial is very very good and walks you step by step.

Regds.
- satya

[This message has been edited by Madhav Lakkapragada (edited January 08, 2001).]
 
pranav vashishtha
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think u need to specify a table name in any sql query. so the statement could be...
delete members from table1 where name = ?
try it.
please do correct me if i'm ignorant of something here.
pranav.
 
Srinath R
Ranch Hand
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String stri= "delete members where name=?";
PreparedStatement pst=con.prepareStatement(stri);
pst.setString(1,username);
the problem is in the second line
"PreparedStatement pst=con.prepareStatement(stri);"
actually the statement should be like
PreparedStatement pst=con.prepareStatement("delete members where name=?");
but u have stored -- delete members where name=? in stri
the statement in the preparedstatement should be with in cotes
and more over their is no table name
this is what i think the problem is kindly let me know if i am wrong

 
ramesh kumar
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI friends
I got the bug, it is nothing but systax error in sql statement
String stri= "delete members where name=?";
in the above line I missed "from" .
that line should be like
String stri= "delete from members where name=?";
thanks for your help .
Hi Madhav , please with me, I am new to Java, that's y I am here.
regards,
K.R.Kumar
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Madhav , please with me, I am new to Java, that's y I am here.
Hi:
I din't mean to offed you or intimidate you, it was a mere
suggestion. I consider myself new to all this stuff. I went
thru the tutorial and realised it is just for newbie's
like us. It walks you step by step.
And, yes this is a great place to start off.
Atleast thats what I found.
Regds.
- satya
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic