473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

JSP: Differing Prepared statements based on if/else logic

108 100+
Greetings,

Im struggling with the very simple task of having TWO different prepated statements based on a string value (code below)


Expand|Select|Wrap|Line Numbers
  1. if(userSelectedCategory != null) {
  2.  
  3.         PreparedStatement myFAQStatement = null, myFAQStatement1 = null, myFAQStatement2 = null;
  4.  
  5.         if (userSelectedCategory == "ALL categories") 
  6.         { 
  7.             PreparedStatement myFAQStatement1 = conn.prepareStatement("SELECT * FROM FAQ");
  8.         }
  9.         else 
  10.         {
  11.             PreparedStatement myFAQStatement2 = conn.prepareStatement("SELECT Id, Category, Question, Answer, Sequence, ViewCount, Rating, UserId, Created, LastUpdated, LastUpdateBy FROM FAQ WHERE Category ='" + userSelectedCategory + "'");
  12.         } 
  13.  
  14.         if(myFAQStatement1 == null) myFAQStatement= myFAQStatement2;
  15.         else myFAQStatement = myFAQStatement1;
It errors with
Duplicate local variable myFAQStatement1
Duplicate local variable myFAQStatement2
Any help would be appreciated, I get confused in java/jsp as with some other languages you can set variables value all over the place without complaints.

Cheers
Rob
Mar 20 '08 #1
2 1569
robtyketto
108 100+
Bump, any advice (I've use this method before for connections choices) ?
Mar 21 '08 #2
JosAH
11,448 Expert 8TB
Leave out the 'PreparedStatement' at the start of line 7 and 11. That way you
don't redefine those two variables. Read a tutorial on Java because this would
happen with any type, not just with PreparedStatements.

kind regards,

Jos
Mar 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sascha Pohlmann | last post by:
hello, I have the following problem: I would like to evacuate the logic from my jsp files in servlets. servlets provide database contents prepared in HTML tables, the jsp files are supposed...
1
by: Tom D | last post by:
I'm rewriting a database interface that our company currently has. Currently it's using the Pear::DB interface, but we found that that was introducing a bit too much overhead. I'm rewriting the...
1
by: LinuxTester | last post by:
If I'm in the rwong newsgroup, please point me where to post I'm plunging into the world of JSP development and I'm wanting to improve on this type of logic: <% int rowCount = 0; %>...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
2
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
4
by: gengyue | last post by:
Hi, I need to call .Net webservice from my JSP page. My application is Struts application. It is deployed on Oracle application server. Here is the whole process. I have a login form. When user...
15
by: josh | last post by:
Hi, I'm a jsp programmer and I have changed work. My boss does not matter about my previous Java experience and so he told me to learn web programming using c#. I have also many Javascript/DOM...
7
by: robtyketto | last post by:
Greetings, I'm slowly building up code to do the following:- Display TWO selection option boxes (cascading). If the FIRST selection option box changes then reload the jsp using onchange...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.