This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Html Input to oracle through servlet and JSP output
jumpa lahari
Greenhorn
Joined: Jan 17, 2008
Posts: 18
posted
0
Hi everyone,
The main aim is to use Html input text, which has to go into the oracle Data base through the servlet and create a table with different columns corresponding To the texts entered in the html and the output should be in the Jsp with the data inside the tables of the oracle database.
What I did , I created a servlet and through the servlet I can connect the oracle database and create the tables and can retrive the data on the console. But I want to connect through the Html to oracle through servlet and output in Jsp and I am using all this in eclipse and the server is tomcat.
Originally posted by Ben Souther: HTML can not connect directly with an Oracle database. Why don't you want to go through a servlet?
Hi Ben,
Yes i am connecting through the servlet and getting connected to the database and getting the data but i want to connect the Html form input to the servlet to the oracle database.
I am unable to make a link between the html and the servlet.
The code below is the servlet code to connect the jsp as well as connectio n to the oracle database.
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">
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">
So here I am able to connect the database but how to send the getParameter() into the database is the main problem.
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 ]
jumpa lahari
Greenhorn
Joined: Jan 17, 2008
Posts: 18
posted
0
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 ]
Thanks Ben,
I go through them and come back to you in a day.
jumpa lahari
Greenhorn
Joined: Jan 17, 2008
Posts: 18
posted
0
Originally posted by jumpa lahari:
Thanks Ben,
I go through them and come back to you in a day.
Hi Ben,
I am using the statement in the java class, I mean in the class which is able to access the oracle database and which is updating and also retrieving the data on to the console.
But my problem is how to make connection between the HTML form Input to the Oracle Database through the java or a servlet class.
As we are getting the parameters from the html text form into servlet by the
But I want this parameters to be added in the oracle database connection class
For example in the below statement I want my parameters be added to the values , so that I can insert data directly into the database from the html form through the servlet but i dont know how to make it can you please bring some light.
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?
kalyan godavarthy
Greenhorn
Joined: Jan 14, 2008
Posts: 5
posted
0
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
live and let livE
jumpa lahari
Greenhorn
Joined: Jan 17, 2008
Posts: 18
posted
0
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?
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
jumpa lahari
Greenhorn
Joined: Jan 17, 2008
Posts: 18
posted
0
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
Hi kalyan,
Thanks for your reply but i haven't got the result.
[ January 22, 2008: Message edited by: jumpa lahari ] [ January 22, 2008: Message edited by: jumpa lahari ]
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.
jumpa lahari
Greenhorn
Joined: Jan 17, 2008
Posts: 18
posted
0
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.
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.
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.
No you didn't. This is the last SQL statement that you've posted:
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?
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?
Hi,
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
I dont think this is correct one in the prepared statement.
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
Can you post the new code/prepared statement calls? It's requiring some imagination to figure out what you are looking at.
jumpa lahari
Greenhorn
Joined: Jan 17, 2008
Posts: 18
posted
0
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.
Hi,
I gave the code like
But the main issue is that, i am unable to find a solution to pass the paramaters when i enter a text in the html file into oracle database through the servlet, please bring some light ,
You set two parameters, but the sql statement only contains 1 question mark. Every ps1.set..() binds a parameter to a question mark. Your line 'ps1.setString(2, "tom")' can't be bound.
Regards, Jan [ January 24, 2008: Message edited by: Jan Cumps ]