Best way to retrieve data for jsp

Hi,
I'm fairly new to java and am preparing to create some jsp's for our intranet. The pages need to include data from a db2 database. I know pretty much what I need to do, but I'm trying to decide the best(most efficient) way to retrieve the data to display. I've looked at a number of examples and the more I look, the more confused I get (it would be so easy on the AS400 which is my background so you can see how new this is to me). I see my options as: using an 'include' statement to include another java file that retrieves the data; or use a java bean; or just instantiate an instance of the class and 'call' the methods for that class directly; or lastly, place all the code directly in the jsp to connect to the database and query the table.
What's the real difference between these options and what's usually the most efficient and preferred way?
Thanks for any advice and clarification.

As a general rule, it's a good idea to separate the
presentation (JSP and HTML) from the business rules
(database access). I know you didn't do that on the
AS/400, you had display files and business logic in
the same program (at least, we certainly do in ours),
but it's a good policy to follow in the web world.
That means, don't put your database access code in
the JSP. Other than that, it depends on the data.
If you have simple data (e.g. customer's name and
d address) then a Java bean would suffice. If you
have complex data (e.g. customer's payment history)
then a bean still might suffice. You would use an
"include" if you had some data (static or dynamic)
that you wanted to appear in several different pages
in the same form.Thanks, I figured putting the code in the JSP was not the best way, but I wasn't sure about the other options.

Similar Messages

  • Best way to export data for a migration

    Hi Oracle Community,
    What's the best way to export data from an Oracle 8i database for it to be suitable for import into an Oracle 10g database?
    What's the best way to export data if it is to go into different rdbms database?
    Thanks, David

    Thanks everyone for all your help. You guys are great.
    There seems to be many good ways to export your data from Oracle into a flat file format, suitable for import into other RDBS': Oracle, mysql, postgresql, etc.
    A few tools where mentioned but using SQL*Plus, which comes with Oracle (And SQL*LDR on the backend, which also comes with Oracle) seem the most straight forward.
    I found this script on asktom.oracle.com to work great, slightly modified here,
    (to Include linesize max, and pipes rather than commas):
    set echo off newpage 0 space 0 pagesize 0 feed off head off trimspool on
    set linesize 32767
    spool payment.txt
    select
    PAYMENT_ID||'|'||
    USER_ID||'|'||
    <more fields her>
    from
    payment
    spool off
    exit ;
    It works great. Rather than making one of these for each table I wrote an perl script called ora_export. http://crowfly.net/oracle/ora_export. It runs in Unix and only requires SQL*PLUS. It creates these four files:
    <tablename>.def # list of table columns and types (SQL*Plus DESC)
    <tablename>_dump.sql  # a script to export the data
    <tablename>.psv # THE DATA (eq. - name|address|etc)
    <tablename>_load.ctl  # SQL*LDR control for ORCL if you need it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • What is the best way to store data for this project?

    hey everyone,
    I have been subscribed to this for a while, not sure if I have ever actually asked anything though.
    I have a project on the go for myself/portfolio
    It is a booking sheet, where by I have a GUI that has a diary system of a day followed by time slots. This also has a date picker that can change the date of the booking sheet
    I want to be able to store mainly strings and ints,
    I need to be able to store, retrieve and on occasion change some data.
    I was looking at using something called JExcelAPI but I cant get that to work at all, I asked for assistance but was refered to here.
    what would be the best way to implement this data storage?
    davyk

    Hey everyone,
    Back again,
    I got this this little snippet of code working but want to ask you guys for a little bit of help on it. if thats ok?
    try
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         String dataSourceName = "mdbTEST";
         String dbURL = "jdbc:odbc:" + dataSourceName;
         Connection con = DriverManager.getConnection(dbURL, "","");
         // try and create a java.sql.Statement so we can run queries
         Statement s = con.createStatement();
         s.execute("create table TEST1234567 ( column_1 char(27), column_2 char(150), column_3 char(150), column_4 char(150), column_5 char(150), column_6 char(150))"); // create a table
         s.execute("insert into TEST1234567 values('"+date+"','"+a+"','"+b+"','"+c+"','"+d+"','"+e+"',)"); // insert some data into the table
         s.execute("select column_7 from TEST1234567"); // select the data from the table
         ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
         if (rs != null) // if rs == null, then there is no ResultSet to view
                    while ( rs.next() ) // this will step through our data row-by-row
              /* the next line will get the first column in our current row's ResultSet
              as a String ( getString( columnNumber) ) and output it to the screen */
                   System.out.println("Data from column_2: " + rs.getString(1) );
         s.execute("drop table TEST1234567");
         s.close(); // close the Statement to let the database know we're done with it
         con.close(); // close the Connection to let the database know we're done with it
    catch (Exception err)
         System.out.println("ERROR: " + err);
         err.printStackTrace();
    }there are more columns, but i cut this code down.
    my question is:
    I think I want a method with an if statement to see whether the table is created or not, if not create it, but how do I go about this? I have searched the API and google, but my brain is fried.
    Also do I always have to do the try/catch and have the code of Class.forname to Statement s in all methods that want to deal with the table?
    davy

  • Ways to retrieve data into Jsp page on ComboBox (or any other event ) event

    Hi all,
    I want to retrieve records from database and display it in Text field.
    Can any one tell me the ways to do it, i know i can do this by using javascript (javascript to submit the form), but i dont want to use javascript any where in my code,
    what i want to know is there any other ways to implement this functionality, and which is the best one.
    Kindly help me,
    Thanks in advanced.

    With plain webapps, there is no way. In one way or another, the server needs to be invoked to be able to provide the data, so that is either a submit or through an Ajax call. Both would involve javascript. Why are you scared of Javascript anyway?

  • Iomega StorCenter ix2-200 device fails when powered. Best way to retrieve data

    Hi, I'm new here because until now I've been lucky enough to experience no issues with my NAS.
    Unfortunately, as of this morning when I power on the ix2 the '!' light blinks red. I can't connect to it through my computer and the desktop Iomega program, under 'dashboard' everything seems as usual except the pie chart showing space usage is not there. But it does still say the device is operating normally. However, when I click on Users or Shared Storage it says 'Disks Not Ready. The selected function is not available due to the state of the disks. Visit the dashboard for details.'
    Can anyone advise me what to do from here? I keep a backup elsewhere but I would like to get a few little things of that have been added since my last backup if possible though, it's not the end of the world if it's not.
    Many thanks, James.

    Can you create new shares? Some users have been able to retrieve their data by adding the shares back by the same name. Not sure if it will be the same case here. A Linux-based device should be able to read from the drives, so there may be an error on the drive or a bad sector possibly. You may need to use a data recovery service to retrieve the data.
    You could try one other thing by accessing the hidden support page.
    Follow the instructions here: http://www.vmcutlip.com/index.php/2013/04/howto-enable-ssh-root-level-access-on-an-iomega-storcenter...
    Select "Recover Disks". I would only do this as a last resort and are not concerned with losing the data.
    Have questions and need answers?
    Search the database for answers to FAQ's, software/driver downloads, tutorials, news, features and more!
    LenovoEMC Support & Downloads
    LenovoEMC North America Support Contact Page

  • Best way to retrieve data from oracle?

    Hi,
    I have a few questions.
    1.)Can a rowtype or a table type returned from oracle database can be retrieved as a dataset or datareader?
    2.)Cursors generally slow down your db(Iam from microsoft sql server back ground). But we seem to be using ref cursors quite a lot here.The only way to return a result as far as i have seen in oracle is to use a ref cursor.Is there any other way?

    Hello,
    1.)Can a rowtype or a table type returned from oracle database can be retrieved as a dataset or datareader?
    I'm not sure how complex your "table types" are -- do you mean PL/SQL Associative Arrays (formerly knowns as "index-by" tables)?
    I believe that %rowtype is a PL/SQL'ism that does not work outside of PL/SQL.
    However, the 11g version of the provider introduced User Defined Types (UDTs) which may be helpful depending on your requirements, etc.
    2.)Cursors generally slow down your db(Iam from microsoft sql server back ground). But we seem to be using ref cursors quite a lot here.The only way to return a result as far as i have seen in oracle is to use a ref cursor.Is there any other way?
    Using a ref cursor is the way to return a result set from PL/SQL to a client. If you are not using PL/SQL then you would not use a ref cursor.
    The .NET Developer Center has good information:
    http://www.oracle.com/technology/tech/dotnet/index.html
    Regards,
    Mark

  • Best Way to Save Data

    Hi all, I'm relatively new to Java, and have a quick question.
    What is the best way to save data in an application, and what is a good rule of thumb when to dive into a database to hold the information. For example a directory of people and their information. I want the program to be able to add/update/delete the information with ease.
    I was reading in Core Java Vol II how to save object data to a file, but it seems tedious if I have to run through a list of objects and save each one. I just want to be able to save records, and retrieve them to edit later.
    Thanks in advance,
    \\//

    UnknownSector wrote:
    Hi all, I'm relatively new to Java, and have a quick question.Hy there, when you find some time, go read [How To Ask Questions The Smart Way|http://www.catb.org/~esr/faqs/smart-questions.html], it will help you in the future.
    What is the best way to save data in an applicationThere is almost never a "best way" to do anything. At least not if you don't define your requirements exactly. It depends on tons of things, that's why there are so many ways to "save data".
    Writing to files and saving to databases are just two of those, and even among those, there are thousand of different ways to handle it.
    , and what is a good rule of thumb when to dive into a database to hold the information.When the data is structured and you want to do queries on it, then you can probably look into a database. When the data is structured and you've got lots of it, then you really should look into databases.
    For example a directory of people and their information. I want the program to be able to add/update/delete the information with ease.Too little information, but I'd tend to go with a database. But then again, I'm going for a DB rather quickly.
    I was reading in Core Java Vol II how to save object data to a file, but it seems tedious if I have to run through a list of objects and save each one.I don't know what exactly you're talking about. Are you talking about serialization? What makes you feel that it is tedious? Can you describe it?
    I just want to be able to save records, and retrieve them to edit later.Well, that can be done in many, many ways. That alone doesn't force you to go one way or another. It's pretty much the definition of "save data".

  • "Failed to retrieve data for this request" occurred when I tried to access a database.

    Hi,
    I installed the sql server 2008 Client on my pc, so that I can connect to a remote sql server 2008 Enterprise cluster.  Here is what happened:
    0. Added myself as a db_owner on the two databases in the sql server cluster.
    1. On my windows xp pro, I typed the server name and log in.
    2. After I logged in, I clicked on the Databases to expand the node.  However, an error prompt says,
    "Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
    The server principal "DomainName\MyName" is not able to access the database "DevicelockDB" under the current security context. (.Net SqlClient Data Provider)"
    I only need to connect to two databases that I created on the sql cluster.  I don't know why the DevicelockDB is needed before I can access two databases.  What does DevicelockDB do?  Do I need it for connecting to a database?  Let me know, thanks in advance.

    I had the same problem , this one resolved the problem , thank you  deshmukhsdineshd
    Best
    Regards
    Tony de Leon

  • What could be the best way to Export data from 11.5.8 instance to 12.1.2?

    Hi All
    What could be the best way to Export data from 11.5.8 instance to 12.1.2?
    Release: 11.5.8
    OS: Oracle Solaris on SPARC (32-bit) verison 9
    DB: 9.2.0.1
    Thanks in advance

    What kind of data you are looking to move?
    Database export/import is only supported for full database export/import and the application release should be the same on the source/target nodes.
    You can move the setup using iSetup or FNDLOAD.
    Thanks,
    Hussein

  • Best ways to view data, total records of an application table ie VBAK

    Hi all,
    What is the best way to view data of an application table in the source system?
    I know about SE16....but are there other ways to know details ie the total no of records and different field information about a
    application table ie VBAK in source R3?
    Also, using SE16 when i checked for VBAK and clicked on the "number of enteries" then it showed 0...however
    when i directly checked from the sqlplus then i found about 5000 records in there in VBAK. I am not sure why
    via SE16 it showed 0. Does anybody have any idea what i missed here?
    Thanks...will give points for ur input.
    ak

    I tried "number of enteried" on se16 and it shows 0 enteries without any selection criterion...i cheked by putting relevant time range as well but it shows 0...
    As i told that when i checked VBAK separately via logging to database directly then i did find 5678 rows there.
    Please note that this is a new demo version....so i thought that i first need to activate the table which i did using tcode SE11. Now the VBAK table is active but still via SE16 shows 0 nuber of enteris....
    Can anybody please advise here..
    Thx
    ak

  • Best way to export data with r.t. prompts and have dense dim mbrs on rows?

    Hi All-
    What is the best way to export data with Run time prompts out of Essbase?
    One thought was to use Business Rules with run time variables and DATAEXPORT command, but I came across at least one limitation where I cannot have months (part of dense Time Periods dimension) on rows.
    I have only two dense dimensions: Accounts and Time Periods and I need both of these on rows. This would come handy when user enter Start and End month and year for data to be exported e.g. If start period is Feb 2010 and end is Jan 2011, I get data for all months in 2010 and 2011.
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000",14202.24,14341.62,14560,13557.54,11711.92,10261.58,12540.31,15307.83,16232.88,17054.62,18121.76,18236
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000",19241,21372.84,21008.4,18952.75,23442.13,19938.18,22689.61,23729.29,22807.48,23365,23915.3,24253
    "CORP1","0173","FY11","Working","Budget","Local","HSP_InputValue","404000",21364,22970.37,23186,27302,25144.38,27847.91,27632.11,29007.39,24749.42,27183.39,26599,27112.79
    where ideally I would need to get the following:
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","Feb",14341.62
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","Mar",14560
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","Apr",13557.54
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","May",11711.92
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","Jun",10261.58
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","Jul",12540.31
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","Aug",15307.83
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","Sep",16232.88
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","Oct",17054.62
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","Nov",18121.76
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","402000","Dec",18236
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","Feb",21372.84
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","Mar",21008.4,
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","Apr",18952.75
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","May",23442.13
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","Jun",19938.18
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","Jul",22689.61
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","Aug",23729.29
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","Sep",22807.48
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","Oct",23365
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","Nov",23915.3
    "CORP1","0173","FY10","Working","Budget","Local","HSP_InputValue","403000","Dec",24253
    "CORP1","0173","FY11","Working","Budget","Local","HSP_InputValue","404000","Jan",21364
    Thank you in advance for any tips.

    Have a read of the following post :- export data to sql
    It may give you a further option.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Best way to read data sources in parallel

    Hi,
    I'm looking for conceptual help as I start a project. I am trying to figure out the best way to get data from several sources at different timings and deliver them to a main vi.
    I have 4 systems, which each work well on their own (OK, one doesn't work yet, but let's assume that can be fixed
    One system reads from 2 pH meters on serial ports. The meters are slow to respond, so it takes about 2 minutes to read 4 channels of data. I save these data to a file every 10 minutes
    One system reads from a CO2 meter on the USB port. It reads the data every second, and does some averaging. Every 2-10 minutes, it saves the average to a file and then sends a command to the parallel port to switch the input to the meter.
    The third system reads from 6 valves, each on a serial port. These also take time, probably several minutes to poll all 6. These data will also be saved to a file.
    The 4th system reads a bank of temperature probes on the USB port. These get polled every few seconds and saved to a file every few minutes.
    Now that these individual routines are working, I am trying to create a front end that will display all the data in one place and allow me to set all the parameters from a single place. I would also like the possibility of using the data from one source at another place (for instance, having the output of the temperature probes sent to the pH meters to adjust their calibration). At this point, I get confused as to the best way to proceed.
    It seems like if I just want to read the data from each source, I could simply put all 4 routines together in a single vi (oh, what a mess that would be to read). Maybe I should start this way?
    However, if I want to have any communication between the different data sources, it seems like I will either need to use queues or VI server. I sort of envision a vi that lets me configure the various ports and the file operations and then can turn on monitoring of any or all of the various inputs. Each of them will do their thing at their own time and the main routine will simply display whatever data they deliver whenever they have new data. Fortunately, nothing is particularly time-critical, nor does it need to run fast.
    My questions: Am I correct in how I'm thinking about getting this to work?   Is there a clear choice between queues or vi server? I've looked at several examples of each, but without having done something like this before, it is hard for me to tell which is better.
    Thanks for any suggestions.
    mike

    Hi Mike,
    I think that you are on the right track with your thinking process. You might be able to implement this using queues. I'm not exactly sure how you would do it with VI server since it is just a set of functions that allows you to dynamically control front panel objects, VIs, and the LabVIEW environment. However, there are some great resources available with using queues for this type of application. I'm including the link to another discussion forum that had a very similar question to yours. There is a good example of using queues within this forum post. Also, there is a great example in NI Developer Zone about using queues and some other good ones in the NI Example Finder (just search 'queues' and you should get a few results). I hope this helps!
    Carla
    National Instruments
    Applications Engineer

  • Best way to pass data sets to another program

    Hey
    I want to connect another (maths) program with my java application. Therefore I need to paste data (some kind of tab separated table) to this program.
    I try now to save these data in a separate newly generated file and to pass a command with Java's Runtime.exec() method to this program to read these data. Is this a good idea or might there be better ways?
    If I do so, is there a way in Java to generate some kind of a "temporary" file which will be deleted automatically after usage or is this nothing else than to save it in a common file and delete it afterwards. What's the best way to pass data generally?

    Well, the connection will not be over a network, so I'd rather think it's not a Socket or RMI problem (unless someone convinces me).
    Yes it's very external, it's a C or C++ written program, I don't have any source codes. So far I generated a file for Input command and data, I passed that on to the maths program and returned the output into another file.
    Now I would like to separate the output and like to obtain some tables and graphical things like charts at the output. Do I have to generate three different types of outputfiles? How to store some graphics e.g. some distributions. I thought even of generating a database. I never thought about XML, I don't know if this works for that kind of problem?!

  • Best way to extract data from archived cube

    Hello Experts,
    Can anyone tell me best way to extract data from archived cube.
    Basically I am trying to pull all the data from archived cube and then load it into another brand new infoprovider which is in different box.
    Also I need to extract all the master data for all infoobjects.
    I have two options in my mind:
    1) Use open hub destination
    or
    2) Infoprovider>display data>select the fields and download the data.
    Is it really possible to extract data using option (2) if records are too high and then load it into another infoprovider in new system.
    Please suggest me the pros and cons for the two options.
    Thanks for your time in advance.

    Hello Reddy,
    Thanks a lot for your quick reply.
    Actually in my case I am trying to extract archived infocube data and then load it into new infoprovider which is in different system. If I have connectivity I can simply export data source from archived infocube and then reload into new infoprovider.
    But there is no connectivity between those two systems (where archived cube is and new infoprovider) and so I am left with the two options I mentioned.
    1) Use Open Hub
    or
    2) Extract data manually from infoprovider into excel.
    Can anyone let me know which of the two options is the best and also I doubt on how to use excel in extracting data as excel have limit of no.of records 65536
    Thanks
    Edited by: saptrain on Mar 12, 2010 6:13 AM

  • Best way to move data and programs to another profile on same Mac?

    Hello,
    What is the best way to move data and programs to another profile on the same Mac? I have a user who's profile is corrupt, I know that most programs will work on both the new and old profile however when trying to copy the Desktop folder, or Documents folder I am getting permissions denied.
    Sort of like weeding a garden, I'm hoping I do not have to pick the data in each folder and copy individually.
    Thanks for your help!
    Johnathon

    This usually means that a configuration or preference file is corrupted.  In this user's /Home/Library/Preferences/ folder locate any preference files associated with iLinc and drag to the Trash.
    I would also check in the /Home/Library/Caches/ folder for a file or folder associated with iLinc and delete as well.
    See if the problem is resolved in the user's normal account.
    It's not that you cannot copy data from account to account, but doing so causes a lot of permissions issues that must be resolved.  The MacFixit article I linked above shows what you need to do after transferring from one account to another in order to change permissions on the "foreign" files to those of the destination account.

Maybe you are looking for

  • Extra characters at end of line in spool file

    I am trying to generate csv files from SQL Developer using queries written to spool files.  I have embedded the queries and associated set commands in script files and call them, as advised elsewhere.  This gives csv files that look fine, with headin

  • Syslog Analyzer and RME4.0.5

    I checked previous discussion regarding this topic and was unable to find a solution.  My syslog analyzer was working at one point, but now it has stopped and I can not get it back to a working condition. It appears the Analyzer is running, but not r

  • Is Oracle 8.0.4 compatible with Win 2000 Advanced Srv

    Sorry this is probably not the right place to post this but if anyone knows or can point me to the right place on how to find out if Oracle 8.0.4 and Windows 2000 Advanced Server with Terminal Server loaded are compatible, I would appreciate it. TIA

  • Windows 7 does not recognize either new HD or returned old HD

    Notebook G61 overheated and shut down.  System Mechanic said HD was near failure, so I replaced it.  Startup disk selected the proper system image and wanted to restore, but hit error code. 0x80042414, saying Windows did not find any disk which it ca

  • Graphics card from G4 to Mac Pro Can it be done?

    I' a proud owner of a Mac Pro! I'm tring to install the Geo Force that came with with my G4 Quicksilver in to my Mac Pro to use as a 2nd monitor,i can't figure out how to install the card somebody out there i hope knows it should be easy to pop it in