Best Practice on querying Data from Database

Hello and I was wondering what is the preferred and best practice for querying data from an SQL database inside a JSP page. Is it using the JSTL library or another method? Thanks

It depends on the size of the application really.
The "correct and preferred" approach in a large MVC app would be to have a seperate class that does all the database access, retrieving the data into java objects.
Check out [url http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html] DAO pattern
You then "save" the data into request/session attributes, and forward to a jsp page to render the result.
Most approaches recommend a separation between JSP (the view) and SQL code.
The JSTL sql tags are provided more for "quick and dirty" code applicable in small applications, or for fast prototyping. That approach is not really robust for large scale applications.
Cheers,
evnafets

Similar Messages

  • Best Practice for Removing Zeroes from Database

    Does anyone have some clever bits of code or best practices for evaluating a database and instances of zeroes? I'm working on cleaning up our rules file and am thinking the best way to start would be to write some code to look for zeroes and write them to a log file. This would at least indicate if there was even a problem with zeroes (which there may or may not be).
    Any suggestions out there / utilities / code samples?
    Thanks.

    We accomplished this using data extracts from a subset of scenarios/years/entities/accounts to ensure that all of our potential rules could be checked to ensure they were not writting zero's. This worked pretty well for our purposes, a text editor called EmEditor allows for VB macros in it pretty easily and we could write a quick macro to check for strings ending in "; 0." You may also want to review your check box of calculated in your extract and see if the zeros are a result of calculations. A rule output could work pretty well, although it would take some defining as you would have to write it out in a sub and make sure that you capture the data of all subroutines if your zero's are rule driven or actual inputs. May want to review some if you have very small insignificant values getting written, seen items that have one value 13 places to the right of the decimal that were not really signficant.
    JTF

  • Best practice to extract data from Hyperion Enterprise 5.5

    We are looking into extracting high-level data from our Hyperion Enterprise 5.5 and am in the process of researching what are the best practices to do that. I am reading the docs for the APIs that I can call from VB6. I am also interested if there are available Java APIs out there.Thanks in advance and Happy Holidays to everyone!Angelito [email protected]

    The easiest is using HAL (Hyperion Application Link). I have used HAL to extract data, organizations, account, subs, entities, etc.

  • Best practice to store date in database

    which best practices do you know to do this?

    Snoopybad wrote:
    which best practices do you know to do this?1. Understand the business requirements that driver the need to store such a value.
    2. Understand the difference between 'time', 'date' and 'timestamp' (date and time) and also understand that a time interval (measurement of passing time) is not the same as any of those.
    3. Understand what timezone means exactly
    4. Look at the database itself to understand exactly how it stores such values. This includes insuring that you understand exactly how the timezone is handled.

  • Having problem querying data from database

    I'm trying to setup a query form to see if the username and password entered is already in a database. If it is then a Static Text will give a positive message, if not then the user would be asked to register. My query doesn't seem to work, since every time I run it the Static Text doesn't show anything after I hit my submit button. Any help would be great.
    public String loginButton_action() {
    // TODO: Process the action. Return value is a navigation
    // case name where null will return to the same page.
    String currentuser = (String) regusernameTF.getValue();
    String currentpass = (String) regpasswordTF.getValue();
    try {
    connection = DriverManager.getConnection(Database_URL);
    statement = connection.createStatement();
    ResultSet resultset = statement.executeQuery(
    "SELECT Username ,Password FROM CustomerInfo" +
    "WHERE (Username =' " currentuser " ') ");
    connection.commit();
    statement.close();
    connection.close();
    String loggeduser = resultset.getString(1);
    String loggedpass = resultset.getString(2);
    boolean compare1 = loggeduser.equals(currentuser);
    boolean compare2 = loggedpass.equals(currentpass);
    if ((compare1==true) || (compare2==true)){
    messageST.setRendered(true);
    messageST.setText("Login Successful");
    else {
    messageST.setRendered(true);
    messageST.setText("Username & Password not Valid." +
    "Please Check Entry or Register to Login");
    catch (Exception e){
    e.printStackTrace();
    return null;
    Edited by: mavrik5150 on Feb 9, 2008 4:49 PM
    Edit: Forgot to mention the Database does have data already populated into it

    Hey Thanks guys for the tips, I was able to fix one problem, now I can get the Static Text field to display a message but I can't get the error message to appear when I purposly enter a wrong password or username. If I enter a correct username I get a successful message, even when I enter the wrong password. Here's the fixed code:
        public String loginButton_action() {
            // TODO: Process the action. Return value is a navigation
            // case name where null will return to the same page.
            Object currentuser =  regusernameTF.getValue();
            Object currentpass =  regpasswordTF.getValue();
            try {
            connection = DriverManager.getConnection(Database_URL);
            statement = connection.createStatement();       
            ResultSet resultset = statement.executeQuery(
                    "SELECT Username ,Password FROM CustomerInfo WHERE (Username ='"+currentuser+"') ");       
    //        connection.commit();
    //        statement.close();
    //        connection.close();   
            while (resultset.next()){
            String loggeduser = resultset.getString("username");
            String loggedpass = resultset.getString("password");
            boolean compare1 = loggeduser.equals(currentuser);
            boolean compare2 = loggedpass.equals(currentpass);
            if (compare1 || compare2){
                messageST.setRendered(true);
                messageST.setText("Login Successful");
            else {
                messageST.setRendered(true);
                messageST.setText("Username & Password not Valid." +
                        "Please Check Entry or Register to Login");
            catch (Exception e){
                e.printStackTrace();
            return null;
        }

  • How to query data from database and store it into Managed Bean ?

    Hi all,
    In our application we have requirement to store information within Managed Bean to be accessed by ADF pages.
    The information is stored in database tables.
    The question is :
    What is the efficient / recommended way to do that ?
    I do not use apps module to query the data because the information is required in View layer not the model layer
    Thank you for your help,
    xtanto

    Xtanto,
    if the information is stored in the database then the question is if there is a database connect open already. If yes, then why not using this connection to query for the data you want to access and store. Alternatively you can directly open a JDBC connection in a managed bean or access an EJB session bean. However, this comes with the price of an extra database connection.
    Make sure the managed bean is in session scope if you want to share the information without re-fetching it
    Frank

  • Query Data From Database and set Visibility Accordingly

    Hi there,
    i have a case where i have to set the rendered property of some items on my screen according to values retrieved from an sql statement.
    When i change a value in a listbox, that value must be given to an sql statement as a parameter (select field_id fom table where id = the value in the list box) to query the ids of the fields from a database table . (each id of a field in my jsf page has the same value in that database table).
    For each record retrieved in that query, the field's rendering having that id must turn to false.
    Anyone can give me a solution to my urgent problem ? ( Where do i write the select statement and the loop and how ... )

    Hi,
    what comes to my mind is to create a custom version of HashMap (extend HashMap) and override the get method. The configure this custom Hashmap as a managed bean. Usually you cannot pass arguments in EL, but for HashMaps this is doable by overriding the get method (at least I remember having done this before).
    So in your EL rendered property value you do
    #{managedHashMapBean["nameOfFieldId"]
    In the bean you just check if the ID exists and if it doesn't return true. So all that your query needs to do is to populate the internal state of the hashmap with the IDs that should be false.
    Frank

  • Best Practice to take data from 11i to 12.1

    Dear all,
    we have 2 instance on linux servers vrsion=5
    1 instance 11.5.9
    2 instance 12.1
    we want to take 11i data to 12.1
    kindly suggest me the best method to achieve it with all validations and everything
    kidnly update
    thank you,
    journey

    Hi hussain,
    we want to take whole data exist in 11i to the traget 12.1 there are many techincla change in them like some table name is change from 11 to 12 so wht whould you sugggest kindly help me.

  • Struts, Best proctices to show data from database in view

    Hi,
    I am using Struts.
    I need to show a result of select operation, some 50-60 records like a grid.
    Best method to transfer ResultSet data to View(jsp) from the Action's execute method. Is it a right way to use a collection of objects, that contains the fields corresponding to the table, populate it first from resultset and iterate in JSP using jstl and <table> to show?
    What is the best method, without altering the MVC?
    Thanks

    Going through the javaee tutorial is one sure way of accelerating your learning curve, as almost every basic you will need to get your job done is explaiined well in there. i have been using it to learn building enterprise application and is awesome good resource.
    seriously consider downloading it
    java.sun.com/javaee/5/docs/tutorial/doc/

  • Best practice for linking fields from multiple entity objects

    I am currently transitioning from PHP to ADF. I'm looking for the best practice for linking data from multiple entity objects.
    Example:
    EO 'REQUESTS' has fields: req_id, name, dt, his_stat_id, her_stat_id
    EO 'STATUSES' has fields: stat_id, short_txt_descr
    'REQUESTS' is linked to EO 'STATUSES' on: STATUSES.stat_id = REQUESTS.his_status_id
    'REQUESTS' is also linked to EO 'STATUSES' on: STATUSES.stat_id = REQUESTS.her_status_id
    REQUESTS.his_status_id is independent of REQUESTS.her_status_id
    When I create a VO for REQUESTS, I want to display: REQUESTS.name, REQUESTS.dt, STATUSES.short_txt_descr (for his_stat_id), STATUS.short_txt_descr (for her_stat_id)
    What is the best practice for accomplishing this? It appears I could do it a few different ways:
    1. Create the REQUESTS VO with a LOV for his_stat_id and her_stat_id
    2. Create the REQUESTS VO with the join to STATUSES performed within the query for the VO. This would require joining on the STATUSES EO twice (his_stat_id, her_stat_id)
    3. I just started reading about View Links - would that somehow do what I'm looking for?
    I also need to be able to update his_status_id and her_status_id through the by selecting a STATUSES.short_txt_descr from a dropdown.
    Any suggestions on how to approach such a stupidly simple task?
    Using jDeveloper 11.1.2.2.0 if that makes a difference in the solution.
    Thanks ahead of time,
    CJ

    CJ,
    I vote for solution 1 as it's just your use case. As you said you what to update the his_status_id and her_status_id through the by selecting a STATUSES.short_txt_descr by a drop down. This is exactly the LOV solution.
    ViewLinks are used fro master detail navigation (which you don't do here) and Joining the data make it difficult to update (and you still need a LOV for the drop down box.
    Timo

  • Query Data from other Oracle Database into current

    Hi all,
    I have to query data from another oracle database into the current oracle database. Because the customer has standard edition, I cannot use a pipe. I tried "SELECT column_name FROM external_oracle_db.schema.table WHERE column_name = 'column_value';" Unfortunately this does not work.
    Does anyone have a suggestion?
    Thanks
    Hans

    Have you tried with Database links?
    SELECT column_name FROM schema.table@external_oracle_db WHERE column_name = 'column_value';
    Satish

  • Best practices to reduce downtime for Database releases(rolling changes)

    Hi,
    What are best practices to reduce downtime for database releases on 10.2.0.3? What DB changes can be rolling and what can't?
    Thanks in advance.
    Regards,
    RJiv.

    I would be very dubious about any sort of universal "best practices" here. Realistically, your practices need to be tailored to the application and the environment.
    You can invest a lot of time, energy, and resources into minimizing downtime if that is the only goal. But you'll generally pay for that goal in terms of developer and admin time and effort, environmental complexity, etc. And you generally need to architect your application with rolling upgrades in mind, which necessitates potentially large amounts of redesign to existing applications. It may be perfectly acceptable to go full-bore into minimizing downtime if you are running Amazon.com and any downtime is unacceptable. Most organizations, however, need to balance downtime against other needs.
    For example, you could radically minimize downtime by having a second active database, configuring Streams to replicate changes between the two master databases, and configure the middle tier environment so that you can point different middle tier servers against one or the other database. When you want to upgrade, you point all the middle tier servers against database A other than 1 that lives on a special URL. You upgrade database B (making sure to deal with the Streams replication environment properly depending on requirements) and do the smoke test against the special URL. When you determine that everything works, you configure all the app servers to point at B and have Streams replication process configured to replicate changes from the old data model to the new data model), upgrade B, repeat the smoke test, and then return the middle tier environment to the normal state of balancing between databases.
    This lets you upgrade with 0 downtime. But you've got to license another primary database. And configure Streams. And write the replication code to propagate the changes on B during the time you're smoke testing A. And you need the middle tier infrastructure in place. And you're obviously going to be involving more admins than you would for a simpler deploy where you take things down, reboot, and bring things up. The test plan becomes more complicated as well since you need to practice this sort of thing in lower environments.
    Justin

  • How to retrieve data from database to the structure(complicated)

    Hello everyone:
           I want to retrieve data from database to the structure. but the structure defined like this below:
    TOLERANZOB LIKE QAMV-TOLERANZOB
    TOLERANZOB1 LIKE QAMV-TOLERANZOB
    so how can I retrieve the data from the database ? make sure that the two fields contain data both.
    Thanks in advance .
    Regards
    Nick

    Hi Nick,
    To retreive data for TOLERANZOB from QAMV,
    If you know the key fields then use
    SELECT SINGLE TOLERANZOB FROM QAMV INTO TOLERANZOB WHERE keyfields.
    else, you can use
    SELECT TOLERANZOB FROM QAMV UPTO ONE ROWS INTO TOLERANZOB WHERE....
    Once you retreive the data using the select query, you can check if it is initial and if not move the data from TOLERANZOB to TOLERANZOB1.
    <b>Reward points for helpful answers.</b>
    Best Regards,
    Ram.

  • Best Practices on Routine Data Load.

    Can someone please tell me what are the best practices on routine data load from one database to another?
    We have PeopleSoft system where new employees' records are created; however, these new employees are required to take new employee tests that is being tracked by an application outside Peoplesoft on an Oracle db. Therefore, we need to populate the Oracle db with the new employee's information - on a daily basis or as needed. The data we will need to track are new employees or rehires, changes on existing employees - position, title, etc, terminated employees - date of termination, etc.
    What is the best practice to get the employee's information to the Oracle db?
    Any suggestions are appreciated.
    -andy

    Depends on your source and your database version which you didn't mention. What is the easiest way to get them out of your source database?
    Perhaps a database link though that might be a security violation.
    Perhaps as a delimited ASCII file loaded using SQL*Loader or an external table.
    Can you provide more information and database version numbers?

  • Not able insert ,query data from forms

    hi,
    I am not able to insert data or query data from forms(10g devsuite).getting error frm-40505,frm 40508 .i am able to insert and select record from sql plus.the block ihave created is control block .it is connected to the table using the properties.
    should i do anything to insert record.please help

    the block ihave created is control block .it is connected to the table using the properties.A Control Block, by definition, is a non-database block. This means the block is not directly connected to a table so you have to manually display data in the block and any DML you want to perform on data in this block you must do manually as well.
    There are four database objects you can base your database block on; 1) a Table, 2) a View, 3) From Clause Query (basically an In-line View), and 4) a database stored procedure. I recommend you use one of these four methods rather than manually display your data.
    Craig...

Maybe you are looking for

  • SAP Service Not Starting in BI 7.0

    Hi All, Today morning my BI 7.0 server restarted twice automatically, then I started the server in last known good configuration after that when I tried to start the server from SAP MMC it didn't started and when i checked the sap service in services

  • SSO with KRB/ADS on Enterprise Portal 7

    Dear All while i am trying to configure SSO with KRB/ADS on Enterprise Portal 7 i am getting this on the trace file..completed the configuration through SpNego and when i try to log in its promting for user name password.. i have attched the trace fi

  • Error while transmitting message.

    All, Newbie here. We are trying a simple file to file scenario - where xi picks up the file from a FTP location and maps the message and dumps it in another FTP location. While we execute this example - we get the following error - <b> "Transmitting

  • [HOWTO] Installing Arch Linux stable release on Acer Aspire One 522

    [This is a work on progress and my first howto ever] These steps will teach you how to install ArchLinux x64 stable release (currently 2010.05) on Acer Aspire One 522 from an existing ArchLinux (your desktop computer) As you need a 2.6.37+ kernel to

  • Video transfer from lumia 920 to pc

    My problem is still unsolved, I have downloaded videos and I want to transfer them to my PC using window 7 operating system. Can someone please help me what to do????