Is this a proper way  of looking in a db-column?

I am trying to check if a string as an email address exist in a database with jsp (by returning true if the string exist). I have managed to do it but I am not sure if this is the best way.
As you see I have used stmt.executeQuery( "SELECT myDbColumn FROM myTable where myDbColumn=myInputStr" ) and checked by if rs.next() returning false or true. Here is my code in short format:
boolean strExist = false;
String myInputStr = request.getParameter("inputStr");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT myDbColumn FROM myTable where myDbColumn=myInputStr" );
   if(rs.next())
      strExist = true;
   else
      strExist = false;
    return strExist;Is this the proper way of checking if a string exist in a db-column???
Thanks

PreparedStatement is indeed the way to go.
Regarding to your code logic: this boolean strExist is less or more superfluous.
Leave it away and just doreturn rs.next();Or if you really, really need it then just dostrExist = rs.next();That said, do you properly close all resources? I see that you're immediately leaving the method block, leaving the statement and the resultset unclosed behind. This is resource leaking. The longer your application runs, the more you do so, your application will crash due to a shortage of DB resources. You need to close all the resources (connection, statement and resultset) as soon as possible. Do it in the finally block of the try block around SQLException in the same method.
I suggest to go through this tutorial to get some useful and proper ideas of how the database access stuff ought to be done: [http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html]. Good luck.

Similar Messages

  • Is this a proper way to check if a string exist in a db-column?

    I don't know I am posting this in the right forum... anyway... I am trying to check if a string as an email address exist in a database with jsp (by returning true if the string exist). I have managed to do it but I am not sure if this is the best way.
    As you see I have used stmt.executeQuery( "SELECT myDbColumn FROM myTable where myDbColumn=myInputStr" ) and checked by if rs.next() returning false or true. Here is my code in short format:
    boolean strExist = false;
    String myInputStr = request.getParameter("inputStr");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery( "SELECT myDbColumn FROM myTable where myDbColumn=myInputStr" );
       if(rs.next())
          strExist = true;
       else
          strExist = false;
        return strExist;Is this the proper way of checking if a string exist in a db-column???
    Thanks

    I responded to your first thread [here.|http://forums.sun.com/thread.jspa?threadID=5374902]

  • Mono voice over has 1 track only is this the proper way to do it?

    My dialogue has 2 tracks (A1/A2), has well has my music (A3/A/4). My voice over, that was recorded in Mono is on just one track (A5), is this fine or should I have 2 tracks also for this voice over?
    Thank you.

    That's not really a great way to handle mono audio, in my opinion. When you double audio tracks, you're literally doubling the audio; all your levels will be jacked up, because you're superimposing sound. What Shane said is what I understand to be the correct way — as far as there's ever a correct way to do anything — to handle mono audio. You pan your left and right stereo tracks to the left and the right, but you keep your mono tracks panned center (or automate the pan for things like foley effects on moving shots, stuff like that).
    Among other things, this makes doing your final mix a lot easier, since you've got only the number of tracks you actually need. Every track you add creates more work when you finish your sound.

  • BC4J datatags: is this the best way to do this?

    In my BC4J JSP application, in the DataTableComponent.jsp, I want to check
    if a property exists on the view object. This is the best way I could come
    up with:
    String PropertyValue =
    (String)dsBrowse.getApplicationModule()
    .findViewObject(dsBrowse.getViewObjectName())
    .getProperty("PropertyName");
    Is this the proper way to get at a view property? Seems like it should be more straightforward.
    Also, does an instance of the ViewImpl class get automatically created when the DataSource tag is used or do you have to specifically instantiate it if you want to use a client method on the view?
    Thanks,
    Steve

    You can do:
       String propVal = dsBrowse.getRowSet().getViewObject().getProperty("PropName");You do not have to instantiate any classes on your own to accomplish this.

  • Proper way to use data throughout a class?

    I know global variables aren't a thing in c#, as that goes against the rules.
    So I have a couple of functions and subroutines (pardon my vocabulary if it isn't canon). I use a simple array to transfer data back and forth. Is this the proper way to do this? As in most efficient, readable, and expandable?
    class Program
    static void Main()
    bool[] MotorPosition = new bool[4];
    MotorPosition[0] = true;
    MotorPosition[1] = false;
    MotorPosition[2] = true;
    MotorPosition[3] = false;
    while (true)
    MotorPosition = UpdateMotorPosition(MotorPosition);
    DisplayMotorPosition(MotorPosition);
    System.Threading.Thread.Sleep(64);
    static bool[] UpdateMotorPosition(bool[] MotorPosition)
    bool[] NewMotorPosition = new bool[4];
    for (int x = 0; x < 4; x = x + 1)
    NewMotorPosition[x] = !MotorPosition[x];
    return NewMotorPosition;
    static void DisplayMotorPosition(bool[] MotorPosition)
    string CombinedDisplay = null;
    for (int x = 0; x < 4; x = x + 1)
    CombinedDisplay = CombinedDisplay + MotorPosition[x].ToString();
    Console.WriteLine(CombinedDisplay);
    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums

    Absolutely amazing! I learn something new every day. I wonder when programming will cease to amaze me.
    using your example jdweng, I was able to add a counter to your code and move the motor position to the test class; as well as add another motor by instancing the class again!
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ConsoleApplication1
    class Program
    static int Main(string[] args)
    Test test = new Test();
    test.Initialize(); //Assigns initial value to MotorPosition
    Test test2 = new Test();
    test2.Initialize(); //Assigns initial value to MotorPosition
    while (true)
    if (test.MotorUpdateCount == 40) Console.ReadLine(); //pauses at 40 to make it easy to see output upto that point
    if (test.MotorUpdateCount > 1000) return -1; //ends program
    test.MotorPosition = test.UpdateMotorPosition(test.MotorPosition); //updates motor 1 position
    test.DisplayMotorPosition(test.MotorPosition); //displays motor 1 position
    if (test.MotorUpdateCount > 20) //at count 20, engages motor 2
    test2.MotorPosition = test2.UpdateMotorPosition(test2.MotorPosition); //updates motor 2 position
    test2.DisplayMotorPosition(test2.MotorPosition); //displays motor 2 position
    System.Threading.Thread.Sleep(128); //slows the loop down to reasonable speed
    public class Test
    public int MotorUpdateCount = 0;
    public bool[] MotorPosition = new bool[4];
    public void Initialize()
    MotorPosition[0] = true;
    MotorPosition[1] = false;
    MotorPosition[2] = true;
    MotorPosition[3] = false;
    public bool[] UpdateMotorPosition(bool[] MotorPosition)
    bool[] NewMotorPosition = new bool[4];
    for (int x = 0; x < 4; x = x + 1)
    NewMotorPosition[x] = !MotorPosition[x];
    MotorUpdateCount = MotorUpdateCount + 1;
    return NewMotorPosition;
    public void DisplayMotorPosition(bool[] MotorPosition)
    string CombinedDisplay = null;
    for (int x = 0; x < 4; x = x + 1)
    CombinedDisplay = CombinedDisplay + MotorPosition[x].ToString();
    Console.WriteLine(CombinedDisplay);
    Console.WriteLine(MotorUpdateCount.ToString());
    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums

  • What is the proper way to create a monotone image with real looking contrast?

    Once I apply a color to my previously created black and white image everything looks washed out.
    I have an artwork with 3D representation of the letterforms, casting shadows on the textured surface. Shadows are deep black. I need this artwork to be colored in gold. My client forwarded me the specs for the metallic gold which he got from the PANTONE. They are:Gold (871); Adobe 1998 RGB: 126-113-76
    HSB*: 44 degrees-40%-50%
    What is the proper way of applying those values to the desired image.
    My idea was to make the image black and white and than create a monotone image with the above specs. In this case the image gets washed out as the darkest black in the shadows becomes this Pantone gold. Is there any other way?

    A duotone will work, however you are going to want to work closely with your printer . Most printers will want the second color in CMYK (Possibly C60 M40 Y0 K100 instead of RGB values or specify a Pantone Rich Black (I personally like 6C)but it will cost you more for the wash up of both heads of the printer...
    Go to Image>Mode>Duotone (image must be greyscale first for this to work) then add the desired colors to your ink scales.

  • I updated my LG G3 this week and now it SUCKS!  When I'm connected to WIFI, nothing on Facebook works.  The photos and videos won't populate.  I have to turn off the WIFI and only use the mobile data. Not to mention, I really hate the way it looks now.

    I updated my LG G3 this week and now it SUCKS!  When I'm connected to WIFI, nothing on Facebook works.  The photos and videos won't populate.  I have to turn off the WIFI and only use the mobile data. Not to mention, I really hate the way it looks now.   Before I updated my phone, I really liked it, now I don't like my phone at all!  When will this be fixed? I hope it's soon.  I'm thinking of changing providers now.

    Does the iOS device connect to other networks? If yes that tend to indicate a problem with your network.
    Does the iOS device see the network?
    Any error messages?
    Do other devices now connect?
    Did the iOS device connect before?
    Try the following to rule out a software problem:                
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on your router
    .- Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Wi-Fi: Unable to connect to an 802.11n Wi-Fi network      
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem and it does not connect to any networks make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • I have Boot Camp running on a separate HD (not a partition on my Mac drive).  I would like to partition the PC HD to have a multi boot PC.  What is the proper way to do this and how do I select which partition to start the PC?

    I have Boot Camp running on a separate HD (not a partition on my Mac drive).  I would like to partition the PC HD to have a multi boot PC.  What is the proper way to do this? How do I select which partition to start the PC?

    I have Boot Camp running on a separate HD (not a partition on my Mac drive).  I would like to partition the PC HD to have a multi boot PC.  What is the proper way to do this? How do I select which partition to start the PC?

  • I have been filling up my internal memory on my laptop after years of video editing. I now want to export all this footage to an external hard drive. What is the proper way to do this.

    I have been filling up my internal memory on my laptop after years of video editing. I now want to export all this footage to an external hard drive. What is the proper way to do this.

    Are the videos being stored in iMovie or another application? Have you exported/shared the video? If the video is in iMovie what version of iMovie are you using? Give as much info as possible, and you may also want to post the question in the iLife section of this forum since more people with video skills will be reading the iLife/iMovie threads.

  • Proper way to pass 'this' to an anonymous listener

    I have added a button to copy some information to the clipboard. Instead of a class-level actionPerformed() method I am using an anonymous listener:
         JButton jb = new JButton("Copy QE");
         jb.setBackground(bgc);
         jb.setForeground(Color.lightGray);
         jb.setToolTipText("copy the information below to the clipboard");
         final HelpBox that = this;
         jb.addActionListener( new ActionListener() {
             public void actionPerformed(ActionEvent e) {
              StringSelection ss = new StringSelection(that.toString());
              Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
              cb.setContents(ss, SIHwheel.logBox);
         });It seems to be working fine. I am wondering, though, is the final declaration of that the proper way? Is there a better overall methodology?

    A common approach is to encapsulate the logic into a method on the enclosing class. Then, the listener would just call the method:
    private void someMethod() {
      // init the JButton...
      jb.addActionListener( new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          updateClipboard();
    private void updateClipboard()
      StringSelection ss = new StringSelection(this.toString());
      Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
      cb.setContents(ss, SIHwheel.logBox);
    }

  • What's the proper way to update this table field?

    I've got a table with a field of TOTAL.  There's a linked table with a field of AMOUNT.  There's one main table record to multiple linked records.   I'd like to replace the TOTAL with the sum of Amount for each link.   I'm
    having a hard time setting up an update query to do that.  Any suggestions?
    ajw

    The proper way is almost certainly not to store the totals in a column in a table at all, but to compute them in an aggregating query, e.g. to return the sum of transaction amounts per customer:
    SELECT CustomerID, SUM(Amount) AS TotalAmount
    FROM Transactions
    GROUP BY CustomerID;
    Storing aggregated values is only necessary if these can legitimately be amended independently of the values from which they are computed.  This is not out of the question, but is rarely the case.
    Ken Sheridan, Stafford, England

  • What is the proper way to record line numbers in Master/Detail records?

    Guys and Gals,
    Been thinking about this for awhile, but thought it best to ask the people who really know what they are doing.
    What is the proper way to record & show line numbers in a Master / Detail record set?
    For example, take Master/Detail relationship Orders and OrderItems. Orders has a column Document_Number and OrderItems has Document_Number, Line_Number. Line_Number should contain the row number 1,2,3,4 ... etc. for each row in a document.
    Should I ...
    <ol><li>Add a sequence and a trigger in the database? The FusionOrderDemo does this, but then the sequence never "resets" and I've got row numbers that keep incrementing. So one document has rows 4,5,6 and the next document has 7,8,9 when they should both have 1,2,3.</li>
    <li>Programmatically take care of the row numbers? This seems like I'm asking for trouble. Anytime an insert or delete operation gets done, I'll have to iterate through rows and re-assign row numbers.</li>
    <li>Is there a way to assign row numbers in a table iterator (or data collection?) to an entity?</li></ol>
    Any suggestions would be appreciated. It's looking like #2 is my only option, but if anyone knows different I'd love the input.
    Will

    Thank you both guys.
    As John said, I believe I'm looking for a gap-free sequence per master record.
    The line number of the OrderItems table is the second half of the primary key. The first half of the primary key (DocumentNumber) is the foreign key to the Orders table.
    Think of it like line items on an order or invoice. For example, if you were talking to someone on the phone concerning an invoice, you might say, "The pricing for line item #3 is incorrect." In this case, it's good to have a common reference. Or imagine a Microsoft Excel spreadsheet with no row numbers displayed! You'd never get anywhere if you had to explain something over the phone.
    If this is tricky to perform, I take it using a sequence and trigger such as the Fusion Order Demo is the best way to approach the challenge for simplicity's sake?
    Will

  • What is the proper way to close all open sessions of a NI PXI-4110 for a given Device alias?

    I've found that, when programming the NI PXI-4110 that, if a the VI "niDCPower Initialize With Channels VI" (NI-DCPower pallette) is called with a device
    alias that all ready has one or more sessions open (due to an abort or other programming error) a device reference results from the reference out that has a (*) where "*" is post-fixed to the device reference where and is an integer starting that increments with each initialize call. In my clean up, I would like to close all open sessions. For example, let's said the device alias is "NIPower_1" in NI Max, and there are 5 open sessions; NIPower_1, NIPower_1 (1), NIPower_1 (2), NIPower_1 (3), and NIPower_1 (4). A simple initialize or reset (using niDCPower Initialize With Channels VI, or, niDCPower Initialize With Channels VI, etc.) What is the proper way to close all open sessions?
    Thanks in advance. Been struggleing with this for days!

    When you Initialize a session to a device that already has a session open, NI-DCPower closes the previous session and returns a new one. You can verify this very easily: try to use the first session after the second session was opened.
    Unfortunately, there is a small leak and that is what you encountered: the previous session remains registered with LabVIEW, since we unregister inside the Close VI and this was never called. So the name of the session still shows in the control like you noted: NIPower_1, NIPower_1 (1), NIPower_1 (2), NIPower_1 (3), and NIPower_1 (4), etc.
    There may be a way to iterate over the registered sessions, but I couldn't find it. However, you can unregister them by calling "IVI Delete Session". Look for it inside "niDCPower Close.vi". If you don't have the list of open sessions, but you have the device name, then you can just append (1), (2) and so forth and call "IVI Delete Session" in a loop. There's no problem calling it on sessions that were never added.
    However - I consider all this a hack. What you should do is write code that does not leak sessions. Anything you open, you should close. If you find yourself in a situation where there are a lot of leaked sessions during development, relaunching LabVIEW will clear it out. If relaunching LabVIEW is too much of an annoyance, then write a VI that does what I described above and run it when needed. You can even make it "smarter" by getting the names of all the NI-DCPower devices in your system using the System Configuration or niModInst APIs.
    Hope this helps.
    Marcos Kirsch
    Principal Software Engineer
    Core Modular Instruments Software
    National Instruments

  • What is the proper way to deal with cascading triggers in AcroForms?

    (this has already been posted in the Scripting forum. Due to the lack of response, I am coming here to the Land of C/C++ Developers)
    What is the proper way to deal with cascading triggers in AcroForms?
    My question refers to the forms in which there is a binary question such as:
    "Are you interested in travel?"
    When the user clicks "Yes", there are further questions whose interactive fields are dot.hidden (or "!"), depending on the answer.
    So far, I can handle the 1-level cases fine, but my doubt is how to implement nested dependencies. For the sake of simplicity, I would prefer to define the cause-effect relationship once ("Every time the 'Interested in Travel' box is checked, the field 'International or Domestic' should be visible") and send some sort of message/trigger downstream.
    I would like the right things to happen (cascading triggers included) when the "Clear Form" menu command is selected.
    Are those desirable features available in JavaScript (the particular JS used by the traditional AcroForms)?
    Maybe I should look into C/C++ programming?
    TIA,
    -Ramon

    I guess my problem is that I have some basic college experience in digital circuit design, and would like the forms to be programmed and behave in the same fashion as digital logic.
    The "Clear Form" menu item, of course, would be equivalent to the  reset button.
    Perhaps it is possible to hook my code onto the "Clear Form" menu item?
    -Ramon

  • What is the proper way to do Color Space Defaults?

    What is the proper way to do Color Space Defaults?   let the color checker chart fill the whole frame or just put the  color checker chart in  front or aside items or people we are gonna shoot?

    I"m not sure how to use this through Direct Link ... as the timeline including all color-space things are locked down. Perhaps going through Sg in a "native" launch with some of the footage, though it would have to be in a codec Sg takes in "native" ... then doing the color chart thing, creating a Look from it, and then applying that in Direct Link sessions might be the process ... but yea, Dennis Weinmann, some advice here?
    Thanks!
    Neil

Maybe you are looking for

  • Best Practice for "flag" columns

    Hello Experts! This is more of a design/architecture/performance? question.  Suggestions welcome, of course! Oracle Server version 11.2.0.3 Scenario: I plan to use one of my columns in the table as a "flag" field.  Meaning, this field will have some

  • Missing page numbers

    I am using dvips to generate ps files. In ghostview, there are page numbers visible. Once printed, however, all the page numbers are gone. What could be wrong? TIA.

  • Software Inventory on Apple Remote Desktop

    Is there a way to pull a software inventory from any machine in ARD without having the same software installed on the server? If I want to check a specific piece of software on a machine it seems I have to have that same software installed on the ser

  • Upgraded home PC to win 10. Still getting used to, seems a bit hardware heavy.

    Upgraded to win 10 pro last night at home. From all I was seeing about it and supporting 8.1 I thought it would not be so different. So far my biggest dislike is you can't tell and inactive window from a pinned icon on the taskbar which is a bit anno

  • Getting Podcasts on my iPod?

    How come some podcasts sync to my ipod and others don't? I see them in iTunes but only some will sync?