Beginner question about prepared statements...PLEASE help! :-)

First let me say thanks for the assistance. This is probably really easy to do, but I'm new to JSP and can't seem to figure it out.
I want to dynamically populate a table that shows whether a particular person has an appointment at a given date and time with a user. To do this, I want to query the MySQL database for the lastname of the person with the appointment that occurs with the user at the year, month, date, and time, in question.
THE CODE BELOW DOESN'T WORK (obviously) BUT SOMEWHAT ILLUSTRATES WHAT I'M TRYING TO ACCOMPLISH:
<%
Driver DriverTestRecordSet = (Driver)Class.forName(MM_website_DRIVER).newInstance();
Connection ConnTestRecordSet = DriverManager.getConnection(MM_website_STRING,MM_website_USERNAME,MM_website_PASSWORD);
PreparedStatement StatementTestRecordSet = ConnTestRecordSet.prepareStatement("SELECT lastname FROM appts_pid1 WHERE user_id='<%=(((Recordset1_data = Recordset1.getObject(user_id))==null || Recordset1.wasNull())?"":Recordset1_data)%>' AND year='<%= yy %>' AND month='<%= months[mm] %>' AND date='<%= dates[dd] %>' AND appttime='16:15:00'");
ResultSet TestRecordSet = StatementTestRecordSet.executeQuery();
boolean TestRecordSet_isEmpty = !TestRecordSet.next();
boolean TestRecordSet_hasData = !TestRecordSet_isEmpty;
Object TestRecordSet_data;
int TestRecordSet_numRows = 0;
%>
The real problem comes in the prepared statement portion. If I build the prepared statement with static values like below, EVERYTHING WORKS GREAT:
PreparedStatement StatementTestRecordSet = ConnTestRecordSet.prepareStatement("SELECT lastname FROM appts_pid1 WHERE user_id='1' AND year='2002' AND month='October' AND date='31' AND appttime='16:15:00'");
But when I try to use dynamic values, everything falls apart. It's not that the values aren't defined, I use the user_id, year <%= yy %>, month <%= months[mm] %>, etc. elsewhere on the page with no problems. It's just that I can't figure out how to use these dynamic values within the prepared statement.
Thanks for reading this far and thanks in advance for the help!!!!

Hi PhineasGage
You are little bit wrong in your
your preparedStatement.
Expression tag within scriptlet tag is invalid.
Whenever you are appending the statement with
expression tag, append it with "+" and remove
expression tag.
Hopefully it will work
ThanksThanks for the response!
I know that the expression tag within scriptlet tag is invalid. I just need a workaround for what I want to do.
I'm unclear what you mean by "Whenever you are appending the statement with expression tag, append it with a "+" and remove expression tag".
Could you give an example?
In the meantime, I've been trying to digest the docs on prepared statements and have changed the code to look like:
PreparedStatement StatementTestRecordSet = ConnTestRecordSet.prepareStatement("SELECT lastname FROM appts_pid1 WHERE user_id= ? AND year= ? AND month= ? AND date= ? AND appttime='13:15:00'");
StatementTestRecordSet.setInt(1,1);
StatementTestRecordSet.setInt(2,2002);
StatementTestRecordSet.setString(3,"October");
StatementTestRecordSet.setInt(4,31);
Again, WITH THE STATIC VALUES, THIS WORKS FINE...but when I try to use expressions or variables like below, things don't work:
StatementTestRecordSet.setInt(2,<%= yy %>);
Obviously, I'm doing something wrong, but there has to be a way to use variables within the prepared statement.
ALSO, the values are being passed to this page via URL in the form:
samplepage?user_id=1&year=2002&month=October&date=31
Based upon this information, is there another way (outside of stored procedures in the db) to do what I want to do? I'm open to ideas.

Similar Messages

  • Question about Regular Expressions, please help!

    I have created an app which reads files and extracts certain data using regular expressions in JDK1.4 using Pattern and Matcher classes.
    However it needs to run on JDK1.2.2 (dont ask). The regular expression classes are not available in 1.2.2 (the Pattern and Matcher class) so i am looking for something similiar which i can use?
    I need something that loops through all the matches found in the file like how Matcher works i.e.
    while (matcher.find())
    // do this
    Help!

    http://jakarta.apache.org/regexp/

  • A question about arrays. Please Help

    Ok here is my question lets say i have a multie varible array such as
    int[][] thisList = new int[3][64];And I have a number of other arrays that are single variable arrays, and which have data stored in them.
    List1[64]
    List2[64]
    List3[64]is there a way i can store all these three list in the multie varible array?
    for example i know i can do this, > Correct me if i am wrong
    List1 = List2; where List1 one now contains all the elements that List2 has.
    but is there a way i can
    us the same format with a multie varible array, to store all three list in it.
    such as thisList[1][] = List1; thisList[2][] = List2[]; Thanks

    for example i know i can do this, > Correct me if i
    am wrong
    List1 = List2; where List1 one now
    contains all the elements that List2 has.There will be one array. Both the List1 and List2 reference variables will point to that same array.
    (By the way, convention in Java is for variables to start with lowercase.)
    >
    but is there a way i can
    us the same format with a multie varible array, to
    store all three list in it.
    such as thisList[1][] = List1; thisList[2][] =
    List2[];
    You can do thisList[1] = List1 if thisList is an int[][] and List1 is an int[]. However, that will not copy any ints. It will just do the same as the above--cause the reference thisList[1] to point to the same array object as List1 does.
    If you want to copy values from one array to another, use System.arraycopy.

  • Beginner question on tween timeline Please help

    Trying to remove the ends of tweened timelines without messing up the complex paths I have created in the beginning of them. If you just drag the tween to the left it compresses all the key frames already placed on the timeline. Example:
    can you eliminate frames 72 to 92 without compressing what was already on frames 1-72? Or maybe I just need to stop it from looping instead. I would really appreciate help. Thank you.

    You should always be able to either remove frames (shift+F5) or remove any keyframe (right-click, remove keyframe) to get rid of keyframes. Frames before the removed frames or keyframes won't be affected.

  • Question about lost iPod - Please help me out!!

    My iPod was stolen and is there anyway to relocate it if it connect to someone's computer? Could Apple track it down? And I am not sure whether I have registered my iPod online. Is there anyway to check??

    Apple have no process in place to either report or track stolen iPods. All you can do is report the theft to the Police together with it's serial number, and if your iPod was registered with Apple when you first got it, they will assist the Police in returning it to you should it ever be recovered.

  • A question about NAST_CREATE_MESSAGE_OBJECT?Please help

    Hello:
       We are now using function:NAST_CREATE_MESSAGE_OBJECT to create an EDI message into NAST in our program.But there is alwasys the following message when NAST_CREATE_MESSAGE_OBJECT is called and then this function will fail.Could you tell me how I can fix this issue?
    Function module SO_NAME_CONVERT with return code
                                                  7
    completed
    No message title for condition type E in
    maintained
    Thanks

    Launch Terminal.app
    Type cd followed by a space. Do not hit return key just yet.
    In Finder, navigate to folder containing the files you want to blow away.
    Drag and drop that folder (in the finder) into the Terminal.app window. It'll autofill the path to the directory containing the files you're wanting to blow away. Now hit the return key.
    You could type ls (that's a lower-case ell) and see the directory listing of all the files in your current directory. Probably a good idea to do just to doublecheck that you really are in the directory that you want to blow away all these files from.
    Now do what Greg said.
    Don't get impatient because Terminal is just sitting there and you're not getting an immediate command prompt. It'll take a while to blow away 9000 files.
    For entertainment, instead of rm *" copy"* use rm -v *" copy"* so you can watch all 9000 file names be printed in your terminal window as they are being deleted.
    Will it work? Oh yes .... irreversibly (if it doesn't, that's coz' there are some file ownership and/or file permission issues that need to be looked at, but assuming those are "compatible" with your current Terminal user environment, those guys'll be toast. Any file that's in the working directory where you are in Terminal that has the five characters " copy" in its filename will be history.
    The assumption in Greg's command is that all the files you want to blow away all reside in the one directory that you have navigated to.

  • A question about firing event, please help

    I would like to know how to fire an event in the following situation:
    public class FireAnEvent
             public static void main()
                   char c=(char)System.in.read())s;
                   String source="I'm the source";
                   if(c!="a")
                          fireActionEvent(new ActionEvent(source,1,null);
    }the above code won't work obviously, but what should i do to make it work, or is it possible to fire in this situation?
    thanks in advance;
    Message was edited by:
    fandebiao

    My personal favourite way to quickly fire custom events is through using enums in the XXXEvent class. That way checking which event was called is easy, and it's also typesafe.
    fireXXXEvent(XXXEvent.ID.MY_ID, "...");
      private List<XXXListener> listeners = new LinkedList<XXXListener>();
      private synchronized void fireXXXEvent(XXXEvent.ID eventID, String args) {
        XXXEvent event = new XXXEvent(this, eventID);
        event.setupOtherStuff(args);
        for (XXXListener l : listeners) {
          switch (eventID) {
            case MY_ID:
              l.xxxAction(event);
              break;
            case MY_OTHER_ID:
              l.xxxOtherAction(event);
              break;
            default:
              break;
      public synchronized void addXXXListener(XXXListener l) { listeners.add(l); }
      public synchronized void removeXXXListener(XXXListener l) { listeners.remove(l); }

  • HT5312 i cannot remember the answers to my security questions.  Can you please help me reset them?

    I cannot remember the answers to my security questions. Can you please help me reset them?

    Alternatives for Help Resetting Security Questions and Rescue Mail
         1. Apple ID- All about Apple ID security questions.
         2. Rescue email address and how to reset Apple ID security questions
         3. Apple ID- Contacting Apple for help with Apple ID account security.
         4. Fill out and submit this form. Select the topic, Account Security.
         5.  Call Apple Customer Service: Contacting Apple for support in your
              country and ask to speak to Account Security.
    How to Manage your Apple ID: Manage My Apple ID

  • I can't remember answers from security questions... Please help me....apple support don't answer.(((

    I can't remember answers from security questions... Please help me....apple support don't answer.(((

    1. See my User Tip for some help: Some Solutions for Resetting
        Forgotten Security Questions: Apple Support Communities.
    2. Here are two different but direct methods:
        a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
        b. Call Apple Support in your country: Customer Service: Contacting Apple for
            support and service.
    3. For other queries about Apple ID see Frequently asked questions about Apple ID.
    4. Rescue email address and how to reset Apple ID security questions
    5. For online assistance use Apple - Support - Express Lane

  • Question about delete statement

    I have question about delete statement...
    i am performing some simple delete statement against one table..but its taking so long..How can we check whether particular delete statements actually deleting records or not..?

    Is the associated select-statement returning rows or not?
    If yes -> delete is deleting
    If no -> delete is just using CPU-cycles
    To tune the delete-statement, you have to tune the corresponding select-statement. To tune the select-statement, you want to read the thread When your query takes too long ...

  • Hi . im forget security questions in apple id please  help me

    im forget security questions in apple id please  help me

    See Here..
    Apple ID: Contacting Apple for help with Apple ID account security
    Or Here  >  Apple  Support  iTunes Store  Contact

  • Hi, Please tell me how can I send the Music Videos to the I Pod From the Computer, I'm so upset about this problem, Please help me ASAP.

    Hi, Please tell me how can I send the Music Videos to the I Pod From the Computer, I'm so upset about this problem, Please help me ASAP.

    Here:
    iTunes 11 for Mac: Set up syncing for iPod, iPhone, or iPad
    or
    iTunes 11 for Windows: Set up syncing for iPod, iPhone, or iPad

  • I forgot the password of icloud and i forgot the security question also can you please help me

    i forgot the password of icloud and i forgot the security question also can you please help me

    it's [email protected]

  • I need answers about the iCloud - Please help

    Hi guys, well I have a few iOS devices, 2 ipads, and an iphone. Well, I got a few questions to ask.
    1. Ok, on my iphone on settings on the icloud bit, I have my iphone back up aswell as the 2 ipads. What will happen if I delete the back up for 1 of the ipads. Like, I don't know whats on the back up. And If I want a new back up for the ipad, how to I create 1?
    2. On the icloud section with all 3 ios devices, my 5gb of storage is full, and each device has a bit of storage used up by it. The iphone - 1.7gb, ipad 1 - 600 mb... And it all adds up to around 5gb. But what I don't understand is, on 1 of the ipads it says I've used up 17gb of storage (not icloud), so why has the icloud only stored 600 mb of it? Shouldn't it store like the whole 5gb? I really don't know... I need all the info about the icloud. And yes I've read all of it on this website but none of it helps.
    3. Since it say the icloud storage is full, how do i get more storage, should I just buy more, or is there another way?
    All I know is, if I have icloud set up on all 3 of my devices, what ever i buy on 1 devices it goes on the other 3.
    And that, i have a back up with all my music n stuff in, just incase something goes wrong. Please help! Thanks!

    iCloud Support
    http://www.apple.com/support/icloud/
    iCloud Help
    http://help.apple.com/icloud/?lang=en

  • Dynamic Prepared statement--pls help

    I need to create a prepared statement where i do not know how many parameters( or arguments i.e " ? ") will be passed. The arguments are decided dynamically while runtime...as in i may pass only a single argument or many.
    example:
    select * from employee_table where employee_id in (?,?....)
    in the above query i may only one employee_id or may be more than one.This is decided during run time.I do not want to run a for loop for the number of employee is as this will cause performance issue. can anybody please tell me how these arguments can be generated dynamically
    thanks 4 ur help in advance

    When will you know the emp.Id ?
    Reason is Once you get the emp.Id at runtime means you can assign this id to string variable using the comma separator and assigned this string to the query.
    Example
    String listOfEmpId = "e11,ee23,e55..."; and then use this variable in the query.

Maybe you are looking for

  • Left outer join problem -- need feedback

    using crystal 2008 haveing prolbems with a left outerjoin to get a blank field(null) to show up. basically i have some po line have have long descriptions or text fields that i want to include with the report. Below is my sql statement. I have writte

  • Random video playing in background

    today i turned on my mac like normal, opened up safari to watch videos online, and this random stuff plays in the background...i recognize it as a video on youtube ive watched before but there is no window to see it or close it nothing is hidden its

  • ITunes shuts down when i try and play a song...

    i upgraded my iTunes to 7.1 (it didnt look like regular upgrade, looked more like an entire installation) i can get in fine but when i click to play music iTunes shuts down with no warning or error...it just shuts down ??? Can someone pretty please h

  • Missing one single Genius-Mix on iPhone

    Hi together, I'm missing one single Genius-Mix on my iPhone 3GS (latest iOS-Version). In my iTunes (latest version) I've got 6 Genius-Mixes, on my iPhone there are only 5 ones; one is missing. I have this problem for weeks. Automatic synchronization

  • Apple sanctioned, official method to revert iOS version?

    Hello! Since installing iOS 6 on my iPod 4G my battery life has gone down drastically. Instead of having 35-45% left of full charge after a nights radio listening (approx 7-8h using Wi-Fi at location), my device is drained. I ve been trying to revert