• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using declaration and scriptlet in JSP

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai,
iam confused with issue of using declaration and scriptlet tag.

in my code i need to initialze Statement,Resultset.....
if i do that as below
<%!
Statement st=null;
ResultSet rs=null,rs1=null;
ArrayList al=null,custal=null;
int pid=0,si=0;
PreparedStatement ps=null;
String enqT=null,poT=null,serviceT=null;
%>at the end iam closing stmt & rs in finlly block

will there be any problem if i do this.coz code in declrtion tag will execute only once & not for every request.

i think thr is no need to initialize in this block.

one more thing wat is the default initial value of String var? null/space

thanx in adv.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I won't comment on your first question, it kills me to see JDBC code in a jsp page

About your second question, String's default value is null.
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would probably be bad to declare a database resource, such as Statement and result within the <%! scriptlet tag, since this becomes an instance variable in the generated servlet. when the JSP page is turned into a servlet by the jsp compiler, where as the contents of <% tags declarations end up inside the service() method of the resulting servlet.

Having a PreparedStatement and a ResultSet variable declared in the <%! as class scoped variables would make your JSP page not thread safe. More than one concurrent request to the page at a given time would cause compete for the class scoped defined variables, the last one to access it would squash it.

So if you must declare JDBC variables on a JSP page, then they should be in the <% tags, not <%! tags.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"heidi psl",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
reply
    Bookmark Topic Watch Topic
  • New Topic