Originally posted by Ben Souther:
HTML can not connect directly with an Oracle database.
Why don't you want to go through a servlet?
Originally posted by Ben Souther:
<form name="input" action="/Database/finish" method="post">
Can you post your servlet-entry and your servlet-mapping from your web.xml file.
Originally posted by Ben Souther:
And your contextPath is "Database"?
If you're not sure, post the full path to your servlet's class file, starting with the drive letter.
Originally posted by Ben Souther:
What is the full path to your servlet's class file on your machine?
Example:
c:\tomcat\webapps\MyApp\WEB-INF\classes\us\souther\MyServlet.class
Originally posted by Ben Souther:
What is the full path to your servlet's class file on your machine?
Example:
c:\tomcat\webapps\MyApp\WEB-INF\classes\us\souther\MyServlet.class
Originally posted by Ben Souther:
Can you connect to your HTML page with a browser?
If so, what URL are you using to do so?
Originally posted by jumpa lahari:
Hi,
This is the http://localhost:8082/DataBaseResult/DataBasehtml.html
Originally posted by Ben Souther:
OK, so your contextPath is DataBaseResult.
The URL in your HTML form doesn't match your contextPath:
<form name="input" action="/Database/finish" method="post">
Try:
<form name="input" action="/DataBaseResult/finish" method="post">
Originally posted by Ben Souther:
Uhmmm.
Why is your database code in your servlet's main method?
Why does your servlet have a main method?
The container is never going to call your main method.
So here I am able to connect the database but how to send the getParameter() into the database is the main problem.
Originally posted by Ben Souther:
You would either build up your SQL query with the values retrieved from the form parameters (not the best way):
Or learn about Prepared Statements.
The first method is error prone, can cause you grief if apostrophes or quotes are present in the form parameters, and opens you up to SQL Injection hacks.
Try Googling for "JDBC Tutorial PreparedStatement" to find tutorials and example code.
[ January 21, 2008: Message edited by: Ben Souther ]
Originally posted by jumpa lahari:
Thanks Ben,
I go through them and come back to you in a day.
live and let livE
Originally posted by Ben Souther:
In my earlier post, I mentioned two ways.
1.) Use the variables created from getParameter calls when building up the SQL string.
2.) Use the methods provided by PreparedStatement (better route).
Have you looked into these?
Originally posted by KALYAN ANAND:
Hi
Copy the code from the servlet into a new method in another new class, send all the parameters you fetch from request from the browser to this method, before that create an object of this new class in the servlet doGet or doPost whatever and then call this method with all the parameters. so 1. enter the values in the browser,2. servlet receives the request and creates an object of new class and sends the parameters to this method,3. this method creates a conn, stmt or pstmt, resultset and does the database part what ever you return back from the databse for either select or insert or update iterate through result set if any and store it in an vector or so and return this vector,4. this vector is used to create the jsp response and so use the printwriter out for writing the response onto the jsp page
thanks
Originally posted by jumpa lahari:
Hi Ben,
I tried to look into the preparedstatement, but i am unable to understand how to send the parameters from the html file.
Thanks
Originally posted by Ben Souther:
Can you show me what code you've written so far for your prepared statement?
Originally posted by Ben Souther:
Look at whatever tutorial you're using again.
Specifically, look for question marks "?" inside the SQL statement.
Read up on those.
See if that gets you going in the right direction.
Originally posted by jumpa lahari:
Ya i looked at the "?" , it is representing the setmethod for the int or string which are invoked by the object created by the preparedstatement, which i did in the code.
Originally posted by Ben Souther:
This thread, at this point, is more about JDBC and PreparedStatements so I'm going to move it to our JDBC forum.
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Jeanne Boyarsky:
I see a few problems in this code snippet.
1) That is not a valid SQL statement. There is a missing = after the word title.
2) There are only two question marks in the query, but the prepared statement sets three parameters.
3) There is no where clause. Do you really want to update every single row in the table with those values?
Originally posted by jumpa lahari:
1)i gave like title =
2)i commented in my code the third statement from the above code.
3)Ya we have to give the where clause , and i tried to give the like
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Jeanne Boyarsky:
Can you post the new code/prepared statement calls? It's requiring some imagination to figure out what you are looking at.
You set two parameters, but the sql statement only contains 1 question mark.
OCUP UML fundamental and ITIL foundation
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |