How to use jdbc in struts ?

i want to connect to database and fire insert, select etc queries but my code should be in struts framework

Struts is only a view-controller framework. MVC implemented properly places the database operations in the model tier. So, I would advise against doing something that seems quick and simple initially (such as firing off JDBC from a JSP).
Rather, use Struts to simply be your VC. Within your model tier, create data access objects. These can use an ORM such as JPA (Hibernate, Toplink, etc.) or vanilla JDBC. My assumption since you are using Struts is that you at least have a Servlet container, likely Tomcat or Jetty. If so, there is documentation for each of those containers on how to set-up a JDBC data source. You can use JNDI within your model tier to access the DataSource (if you are using plain JDBC) or to supply the connection information for your EntityManagerFactory (if using JPA).
If you are not sure how to even perform database access, I would recommend taking a JDBC tutorial. Do so standalone and not bothering with Struts or even Servlets. Once you have JDBC down, you can proceed to JPA and/or then integrate with Struts.
- Saish

Similar Messages

  • How to use JDBC Connection Pools in a standalone application?

    Hi, there,
    I have a question about how to use JDBC Connection Pools in an application. I know well about connection pool itself, but I am not quite sure how to keep the pool management object alive all the time to avoid being destroyed by garbage collection.
    for example, at the website: http://www.developer.com/java/other/article.php/626291, there is a simple connection pool implementation. there are three classes:JDBCConnection, the application's gateway to the database; JDBCConnectionImpl, the real class/object to provide connection; and JDBCPool, the management class to manage connection pool composed by JDBCConnectionImpl. JDBCPool is designed by Singleton pattern to make sure only one instance. supposing there is only one client to use connection for many times, I guess it's ok because this client first needs instantiate JDBCPool and JDBCConnectionImpl and then will hold the reference to JDBCPool all the time. but how about many clients want to use this JDBCPool? supposing client1 finishes using JDBCPool and quits, then JDBCPool will be destroyed by garbage collection since there is no reference to it, also all the connections of JDBCConnectionImpl in this pool will be destroyed too. that means the next client needs recreate pool and connections! so my question is that if there is a way to keep pool management instance alive all the time to provide connection to any client at any time. I guess maybe I can set the pool management class as daemon thread to solve this problem, but I am not quite sure. besides, there is some other problems about daemon thread, for example, how to make sure there is only one daemon instance? how to quit it gracefully? because once the whole application quits, the daemon thread also quits by force. in that case, all the connections in the pool won't get chance to close.
    I know there is another solution by JNDI if we develop servlet application. Tomcat provides an easy way to setup JNDI database pooling source that is available to JSP and Servlet. but how about a standalone application? I mean there is no JNDI service provider. it seems a good solution to combine Commons DBCP with JNID or Apache's Naming (http://jakarta.apache.org/commons/dbcp/index.html). but still, I don't know how to keep pool management instance alive all the time. once we create a JNDI enviroment or naming, if it will save in the memory automatically all the time? or we must implement it as a daemon thread?
    any hint will be great apprieciated!
    Sam

    To my knoledge the pool management instance stays alive as long as the pool is alive. What you have to figure out is how to keep a reference to it if you need to later access it.

  • How to use JDBC Lookup in PI 7.1 ?

    Hi,
    Please advise how to use JDBC lookup in message mapping PI 7.1 ? any reference link / document  ?
    I have followed this step below :
    1. Create the external definition for the database table.
    2. Use the external definition (table) in message mapping JDBC Lookup.
    But the target still "Yellow colour" meanint the mapping hasnot completed yet ? why ? and when i double click the JDBC lookup
    there some error message
    "No suitable parameter found; define new parameter of type 'Channel' first"
    Please advise.
    Thank You and Best Regards
    Fernand

    Hi Fernand,
    JDBC Lookup can be done in PI 7.1 using below mentioned steps :
    1) Create a communication channel between PI and the database to connect to database.
    2) Import the table data as External Definition.
    3) In message mapping where this lookup is to be used select JDBC Lookup under Conversions and map
    4) Double Click on JDBC Lookup
    5) Select parameter and a database table (imported as the external definition). All the elements of the table will appear in the middle column. Select and move the input parameters to the left side column and the output parameters to the right side column. Click OK. 
    6) Under message mapping go to signature tab and define the parameter as channel and category as JDBC Adapter Type. 
    7) Under Operation mapping define the parameter & associate it with parameter defined in Message Mapping.
    Thanks
    Amit

  • Is there any documentation on how to use JDBC in ALBPM?

    I'm trying to connect to a DB using DriverManager class.
    1) I've defined an externalResource of type SQL Database.
    2) When I execute the following code:
    //externalResourceURL is the URL of the SQL Database external resource created in 1), same for user and password
    con as java.sql.Connection = DriverManager.getConnection(arg1=externalResourceURL, arg2=user, arg3=password)
    3) I get the following error: This driver is locked for use with embedded applications.
    Is there any tutorial or documentation on how to use JDBC in ALBPM?
    Thanks in advance

    I don't know of any documentation off hand... but what are you trying to do? I haven't needed to to make a connection using the DriverClass....
    If you aren't using dynamicSQL... you can just catalog the database, and make direct sql calls (not recommended)... but if you catalog it, then just an INSERT command works... or UPDATE... etc
    logMessage "Starting insert."
    INSERT INTO MYTABLE(id, name) VALUES ("2", "kevin");
    logMessage "Finished insert."Check out the studio help under SQL Keywords for more info on that...
    HTH
    -Kevin

  • How to use JDBC driver (type 4) with struts?????

    Hi! have a nice day!!!!!
    i want to connect database use struts with JDBC driver type 4. i must add <data-source/> to <data-sources></data-sources> tag but i don't know how to use <data-source/> with it's properties. please tell me! thank very much

    thank for reply!!! :D
    my project require to use struts 1.2.8 with ODBC (i think so it's type 1) for connect to database (SQL server). i think so it has two step :
    1. edit file struts-config.xml with <data-sources> tag.
    2. programming in file java (which extends from Action class) connect to database.
    but how to programming in file java??? (i think so must use objects DataSource & Connection)

  • How to use displaytags with struts

    How to use display tags with struts to generate report from database

    I think it would only consist in including the tag library of displaytags in the header and use the prefix of desplay tags.
    Exporting the report from a database would only need to retrieve this information from the database as a List, Map or Collection of objects (beans) and display tem with the corresponding tag (table)
    You have some more information here:
    http://displaytag.sourceforge.net/11/tut_basic.html
    Regards and good luck,
    Fran Serrano.

  • How to use jdbc to connect oracle

    I want use jdbc direct to connect oracle database,and I
    want to use sun Company or oracle Company driver. how can I get driver and how do I write connection string?
    Deeply to wait your reply,thank you!

    The correct format would be jdbc:oracle:thin@server:port:sidTry "jdbc:oracle:thin:@192.168.84.20:1521:ORDB","ysys","fareast"and see what happens.
    Note that you two formats for the DriverManager.getConnection() method; if DriverManager.getConnection(db_url, username, password) doesn't work, try the other call with a fully-qualified database url:DriverManager.getConnection("jdbc:oracle:thin:ysys/[email protected]:1521:ORDB")The SID is the server ID that was given to the instance when the database was installed; default is ORCL, but may have been changed. Port default is 1521, but again, this may be different for your system.

  • How to use JDBC iView to get data from MSSQL

    Hi Guru,
    I just try to follow the Demo (from SDN) to use JDBC iView. In the step of selecting query or existing function, I choose the query option to broswer the table. But the system is not display any tables. It just keep on displaying 'Loading ...'. Is there anything wrong with that?
    Thanks for your help,
    Bo

    Hi Bo,
    I got the same problem with your, do you know how to fix the problem?
    Thanks,
    Ku

  • How to use JDBC II and III Type Drivers?

    Hi To All
    I am learning JDBC Programming in Java. i got some couple of examples on JDBC I and IV type of Drivers. but i am not able to understand, and use 2nd and 3rd Type of JDBC Drivers. i did not find those examples anywhere. if you know how to use them, please help me. Thanks in advance.

    that's not for you to worry about. The native code is part of the driver, and supplied with it.
    In other words, the driver calls some DLL (or whatever, depending on operating system) which is most part of or calls the database client also installed on the client.
    This in turn calls the server.
    Your Java code never notices all that going on under the hood, except that it may well be slightly slower than using a type 4 driver (depending on the database, some may have highly optimised native network traffic, which is so much faster than the IP traffic of a type 4 driver that it makes up for the extra work needed to communicate between applications and application layers).

  • How to use internationalization in struts

    how to use the internationalization in struts with clear example

    http://www.google.com/search?hl=en&q=ajax+struts&btnG=Google+Search

  • How to use JDBC database connection in Solaris

    Hi all,
    I am new to Solaris and i want to create an application using JDBC database connection.
    I want a small piece of code, probably a login page code that verifies the username from a OpenOffice database (.odb) file. I am particular to know the driver name, etc. If possible give the code using JNDI loopkup.
    Thanks in advance,
    Parasou.

    Sure no problem.
    Please stand by while I do your work for you.

  • How to use JDBC to connect Oracle databse

    Hi
    I try to connect the oracle databse by using JDBC. But I not sure whether is it correct or not because I learnt from the documentation provided by WWW.JAVA.SUN.
    I have create a ODBC DSN file call TKS username/password : tem/manager
    then I download the source code and enhance a bit as following :
    import java.sql.*;
    public class CreateCoffees
    public static void main(String args[])
         String url = "jdbc:oracle:thin:tem/manager@(
         description=(address_list=(
         address=(protocol=tcp)
         (host=192.9.200.8)(port=1521)))(source_route=yes)
         (connect_data=(sid=tks)))";
    Connection con;
    String createString;
    createString = "create table COFFEES " +
    "(COF_NAME VARCHAR(32), " +
    "SUP_ID INTEGER, " +
    "PRICE FLOAT, " +
    "SALES INTEGER, " +
    "TOTAL INTEGER)";
    Statement stmt;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
         catch(java.lang.ClassNotFoundException e)
    System.err.print("ClassNotFoundException: ");
    System.err.println(e.getMessage());
    try {
    con = DriverManager.getConnection(url, "tem", "manager");
    stmt = con.createStatement();
    stmt.executeUpdate(createString);
    stmt.close();
    con.close();
         catch(SQLException ex)
         {  System.err.println("SQLException: " + ex.getMessage());
    After that I saved the file as CreateCoffees.java and compiled it
    D:\KLTAY\JAVA>javac CreateCoffees.java
    CreateCoffees.java:6: unclosed string literal
    String url = "jdbc:oracle:thin:tem/manager@(
    ^
    CreateCoffees.java:10: unclosed string literal
    (connect_data=(sid=tks)))";
    ^
    CreateCoffees.java:30: cannot resolve symbol
    symbol : variable con
    location: class CreateCoffees
    con = DriverManager.getConnection(url, "tem", "manager");
    ^
    CreateCoffees.java:31: cannot resolve symbol
    symbol : variable con
    location: class CreateCoffees
    stmt = con.createStatement();
    ^
    CreateCoffees.java:34: cannot resolve symbol
    symbol : variable con
    location: class CreateCoffees
    con.close();
    ^
    5 errors
    Please give some advise.Thanks
    best regards,
    Tay

         String url = "jdbc:oracle:thin:tem/manager@(
         description=(address_list=(
         address=(protocol=tcp)
         (host=192.9.200.8)(port=1521)))(source_route=yes)
         (connect_data=(sid=tks)))";
    After that I saved the file as CreateCoffees.java and
    compiled it
    D:\KLTAY\JAVA>javac CreateCoffees.java
    CreateCoffees.java:6: unclosed string literal
    String url = "jdbc:oracle:thin:tem/manager@(
    ^
    CreateCoffees.java:10: unclosed string literal
    (connect_data=(sid=tks)))";
    ^I would suggest putting all code between the quotesj(") on one line and then attempting to recompile.

  • How to use JDBC to connect informix database

    Dear all,
    I want my client application to connect informix database by using JDBC. The JDBC driver has been installed successfully in the client computer (Win2000). The informix 5.0 resides the a Unix server named "dbserver". The following is my java program.
    ========================
    import java.sql.*;
    import java.awt.event.*;
    public class Application1 {
    public static void main(String[] args) {
    Connection conn;
    try
    Class.forName("com.informix.jdbc.IfxDriver");
    catch (Exception e)
    System.out.println("Error "+e.getmessage());
    e.printStackTrace();
    return;
    System.out.println("It is ok");
    try
    conn = DriverManager.getConnection("jdbc:informix-sqli://dbserver:1526:INFORMIXSERVER=dbserver;username=test;password=******");
    catch (SQLException e)
    System.out.println("ERROR ."+e.getMessage());
    e.printStackTrace();
    return;
    System.out.println("All is fine");
    ===========================
    However, the error appears mentioning "Attempt to connect to database server (dbserver) failed." I don't know what the problem is because my informix database server is exactly "dbserver".
    Kindly need help from you guys. Thanks in advance.
    Kevin

    Hi,
    Plz try this (instead of 'username' use 'user') ...
    DriverManager.getConnection("jdbc:informix-sqli://dbserer:1526:INFORMIXSERVER=dbserver;user=test;password=*****");
    or this (pass the username and password as params)....
    DriverManager.getConnection( "jdbc:informix-sqli://dbserer:1526:INFORMIXSERVER=dbserver" , "test" , "*****" );
    Hope this helps
    ssa.
    >
    I want my client application to connect informix
    database by using JDBC. The JDBC driver has been
    installed successfully in the client computer
    (Win2000). The informix 5.0 resides the a Unix server
    named "dbserver". The following is my java program.
    ========================
    import java.sql.*;
    import java.awt.event.*;
    public class Application1 {
    public static void main(String[] args) {
    Connection conn;
    try
    Class.forName("com.informix.jdbc.IfxDriver");
    catch (Exception e)
    System.out.println("Error "+e.getmessage());
    e.printStackTrace();
    return;
    System.out.println("It is ok");
    try
    conn =
    onn =
    DriverManager.getConnection("jdbc:informix-sqli://dbser
    er:1526:INFORMIXSERVER=dbserver;username=test;password=
    catch (SQLException e)
    System.out.println("ERROR ."+e.getMessage());
    e.printStackTrace();
    return;
    System.out.println("All is fine");
    ===========================
    However, the error appears mentioning "Attempt to
    connect to database server (dbserver) failed." I don't
    know what the problem is because my informix database
    server is exactly "dbserver".
    Kindly need help from you guys. Thanks in advance.
    Kevin

  • How to use coolies in struts

    hai
    i got answer for this in O'Reilly Jakarta Struts Cook Book....
    thanks...

    I don't think you should use coolies in struts at all. Or for anything at all. I abhor slavery of any kind

  • How to use cookies in struts

    hai
    iI am new to struts. I want to get value in text field from one form to another using cookis in struts, can any one help me?, please...

    To write a cookie in Struts, you create one and add it to the response object. (response.addCookie(cookie)).
    To read it, you use the bean:cookie tag.
    As to use cookies to get a given value from one form to another, there might be better ways, like using request attributes.
    You might be better off keeping those cookies in the jar, after all.

Maybe you are looking for

  • Regarding when we are implimenting mm in sap bw?

    Hi bw gems i had one dought, that is when we are implimenting mm in sap bw on have some standard settings in R/3  what is that settins and why we are doing that settings plz           its very urgent..

  • Unlocking head tag in template/procedure unclear to me

    Hi, Still battling since last friday to unlock head tag in template so that i could add an accordion in a template-based doc. I understand that in the process of creating an accordion DW cs3 has to write something like this in head: <script src= "../

  • KQRCMT: Write failed with error=604 Errors in Trace File

    Anyone know what errors like these in the trace file might indicate? I'm trying to diagnose why one of our application processes died without warning, and found this in the process trace file right about the time when it died. My Oracle Support turns

  • How do I go about moving forward on transactional licensing program?

    Our higher ed department is interested in purchasing options for the transactional licensing program. The TLP info points to sales inquiry number who in turn pointed one of our techs back to the TLP website for information on purchasing. How do we ge

  • No output from java stored procedure

    Hi all, I'm calling my java stored procedure as follows. In my java code I have several System.out.println statements, but none of them are displayed. Any suggestions or explanations? Thanks, Melani spool $ORACLE_BASE/local/logs/execjava_prod.log set