JSP: Data retrieval from database

Hi Everyone...

I know that inorder to extract a value from a database and output to the screen the syntax will be

<%= rst.getString("DeliveryID")%>.

But what if I want to extract the value from the database and instead of outputting to the screen, I want to assign it to a variable I have declared.

I tried the following but it did not work:

<% String name = request.getString("DeliveryID"); %>.

I hope someone can help me out in this.

regards

BabyJava

[521 byte] By [BabyJavaa] at [2007-11-26 21:12:04]
# 1
hi,<%! String obj = rs.getString("ColumnName");%> NB: Use expression language instead. http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSTL.html#wp74644 http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSTL7.html#wp63722
java_2006a at 2007-7-10 2:49:39 > top of Java-index,Java Essentials,New To Java...
# 2
@OP: a jsp should just concentrate on the view, i.e. the html to beproduced. Never should it have to deal with databases. Recheckyour design.kind regards,Jos
JosAHa at 2007-7-10 2:49:39 > top of Java-index,Java Essentials,New To Java...
# 3
I totally agree with @JoaSH. A JSP should be used in the view layer of your web application. But, if you'd like an example : http://www.java2s.com/Code/Java/JSTL/SQLTagOutExamples.htm
java_2006a at 2007-7-10 2:49:39 > top of Java-index,Java Essentials,New To Java...
# 4

Hi Guys...

Really thanks for the advice, I guess you guys are right. But it's too late for me to change anything now so I am more or less stuck with the existing design. I have got one new problem though.

I want to update all values of a table at once and this is the SQL statement I used, but it's not working. I guess the problem could be with the way I am using the wildcard. Here is the code:

String query = " UPDATE Customer SET CustomerID = '"+CustID +"'," +

" CustomerName = '"+CustName+"', CustomerPassword = '"+CustPassword+"', " +

" CustomerType = '"+CustType+"' , CustomerAddress = '"+CustAddress+"' ," +

" CustomerHandphone = '"+CustHandphone+"'" +

" WHERE CustomerID LIKE 'C%' ";

I am getting a general error. Is there anything wrong with my code?

regards

BabyJava

BabyJavaa at 2007-7-10 2:49:39 > top of Java-index,Java Essentials,New To Java...