aspose file tools*
The moose likes Servlets and the fly likes simple coding, still not working, may day!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "simple coding, still not working, may day!!!!" Watch "simple coding, still not working, may day!!!!" New topic
Author

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

ramesh kumar
Ranch Hand

Joined: Nov 16, 2000
Posts: 32
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

Joined: Jun 03, 2000
Posts: 5040
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).]


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
pranav vashishtha
Greenhorn

Joined: Oct 03, 2000
Posts: 3
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

Joined: Jun 28, 2000
Posts: 71
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

Joined: Nov 16, 2000
Posts: 32
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

Joined: Jun 03, 2000
Posts: 5040
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
 
subject: simple coding, still not working, may day!!!!