Database access from flex thro java objects

Please tell me how to access the data from the MS SQL server
through a java object and connect it to flex and display the data
in flex.
please provide me the code for this assignment.
Thanks in Advance.
Selvakumar.

What would you consider when choosing between FDS and PHP
(via HTTP) for mySQL communication?
My app doesn't need to be real time but I am concerned about
the load on the webserver running PHP. Is that a typical point of
failure?

Similar Messages

  • Database access from session bean

    Hello,
    I have a stateless session bean which performs some complex
    calculations, and also does some database access.
    For the database access the bean class has a datasource as
    follows:
    public class TestBean implements SessionBean {
    private DataSource ds_;
    public void ejbCreate() {
         getDataSources();
    private void getDataSources() {
         try {
         Context ictx = new InitialContext();
         ds_ = (DataSource)ictx.lookup("java:comp/env/jdbc/TestDB");
         } catch (Exception e) {
         e.printStackTrace();
         throw new EJBException(e);
    Now this class has a method (which is also in the remote interface)
    calculateSomething(). This method constructs a number of other
    objects that do the actual calculation, and one of these objects
    does the actual database access. How would another object be able to
    use the datasource that was constructed in the bean class?
    I could pass the datasource reference to that object, but that would
    break my encapsulation. This is because that object does not get
    created directly by the bean object, but rather the way the objects
    interact is something like A -> B -> C, where A is the TestBean, and
    C is the object that does the DB access. If I passed the datasource,
    I would need to make B aware of the datasource, which doesn't
    seem good design, because B doesn't do any database access.
    Alternatively I could do the lookup in class C, but that would
    degrade the performance, as an object C gets created and destroyed
    every time the calculateSomething() method is called.
    A third option I have thought of, is to add a public method to the
    bean that returns a connection. Whenever another object gets
    created, a reference to the bean object will be passed along. Then,
    if another object needs to do database access, it will call back
    the bean to get a connection. This seems just as bad (if not worse)
    than the first option.
    Does anyone have an elegant solution for this situation? What is
    the best practice of handling datasources when a bean class doesn't
    do the database access itself? In all the examples I've seen so far,
    all the functionality was in the session bean class, but again that
    doesn't seem good OO design, and would result in a single huge class.
    regards,
    Kostas

    Thanks again to both for the replies. Here are my responses:
    Yi Lin: Yes, I know that an entity bean would solve this problem, however it has been decided not to use entity beans so this is not my call (I think the reason entity beans are not allowed in this project is that they are considered risky: there are other applications that access the same database, so if the container caches entity bean data as you describe, then the users might get inconsistent results).
    Gerard: Actually object B is the one that has the business logic and C is a peer object that only does database access and no calculaitons. For example B can be Customer, and C CustomerDB. This is why object B does not have any knowledge of datasources or connections. So my design does not appear to be that bad!
    As far as the factory you propose is concerned, I cannot understand how this would solve my problem. In order to solve this situation the factory would need to be persistent, i.e. get created by the ejbCreate() method, and destroyed whenever the container decides to destroy the bean. There would be no point in object C creating the factory, as I would have the overhead of doing the JNDI lookup every time I create a C.
    So the question remains the same: how would I pass a reference to the factory from A to C without making B aware of it?

  • How to enable database access from Java or CSharp ?

    I set up an Oracle Express database on my local computer.
    Now I want to connect to this databsee from a CSharp (or Java) program.
    How do I have to specify the connection string?
    The following does NOT work:
    connectionstring = "Data Source=XE;User Id=karl;Password=mypassword";
    connection = new OracleConnection(connectionstring);
    connection.Open();
    I am getting an error
    "Invalid argument" ORA-12532 error
    How do I have to specify the connection string otherwise ?
    Is the sequence of the parameter Data Source, User Id and Password
    important ?
    How do I get a more detailed error message from Oracle ?
    Do I have to enable the accessibility from outside programs
    in Oracle somewhere ?

    about to the error:
    ORA-12532 TNS:invalid argument
    Cause: An internal function received an invalid parameter. This message is not normally visible to the user.
    Action: For further details, turn on tracing and re-execute the operation. If the error persists, contact Oracle Support Services.
    Regards

  • Code generation: from resultset to Java Object

    Hello all:
    Is there any utilities that can convert the ResultSet to a list of Java objects? I think that's doable, since we can get the metadata from ResultSetMetaData anyway, which provide a means to construct the internal properties of a java object.
    I just wonder if there is already something doing that out there... rather not to reinvent the wheel...
    Thanks,
    John

    thanks to both.
    You don't create data objects from data rather your data exists within the data objects. Thus the code that is going to use the data objects must already know the form so they can do something intelligent in the first place.So much better to start with a data model and then create code from that then populate from the database.
    >
    Here I just explore the idea and assess its viability. The project is using a cache solution, coherence as matter of fact. it seems the idea is to return a data strcture like a generic resultset from the cache. my understanding is that, when a user sends out a SQL, the database designer wouldn't know the POJOs the user uses from their side, still database is able to return a resultset from which the user will have enough info to populate their POJOs.
    I will take another look at the design, but meanwhile I found BasicDynaBean from apache's bean utilities useful, and came out with the following code:
    public List<BasicDynaBean> execute(final RequestObject ro) throws SQLException {
              List<BasicDynaBean> list = jdbcTemplate.execute(
                        new CallableStatementCreator(){
                             @Override
                             public CallableStatement createCallableStatement(Connection con)
                                       throws SQLException {
                                  CallableStatement cs = con.prepareCall(spName);
                                             // code skipped
                                                                                                    return cs;
                        new CallableStatementCallback<List<BasicDynaBean>>(){
                             @Override
                             public List<BasicDynaBean> doInCallableStatement(CallableStatement cs)
                                       throws SQLException, DataAccessException {
                                  cs.execute();
                                  ResultSet rs = (ResultSet) cs.getObject(outputPos);
                                                                                                    //apache api to convert the rs to list of BasicDynaBean     
                                  RowSetDynaClass rsdc = new RowSetDynaClass(rs);
                                  List<BasicDynaBean> rows = rsdc.getRows();
                                  return rows;
              however, I noticed that each mean contains the column headers, seems to me it's quite a overhead!
    thanks, John
    Edited by: Johnny_hunter on Aug 1, 2011 10:49 AM
    Edited by: Johnny_hunter on Aug 1, 2011 11:57 AM

  • Database Access from JSP - Is it correct?

    From a JSP Page, we need to retreive data from the database. We have our own application specific API commands to retreive data from database. We have doubts in using this API commands.
    Approach 1:
    From the jsp, send the query details to a Java file (BO). From the java file (BO), call the database and retreive the data
    Approach 2:
    Use the API command directly from the jsp page to retreive details from the database.
    In both approaches, the same API command is going to be used. We just want to know is there any advantage in calling the database through the java file (BO) instead of directly from the jsp?
    Regards,
    R.Aravinth

    Thanks Ram. But we are not going to have any complex
    codes written for data retreival. We just epxect a
    single line of code which will call database and that
    API command will return us a storage variable which
    we will use for displaying purpose.
    ok take a look at this
    //code to display lot of other stuff
    <%
        try {
           //code to access db and get data;
        catch(SomeException e){
            //oh-oh you are already on the display logic and have output a lot of stuff
            //how do you handle this
    %>versus this
    //code in some handler or bean
       try{
               //code to get data
              //set an attribute to enable a redirect to jsp page
        catch(Exception e){
              //handle exception, log ?
              //set an attribute to enable a redirect to error page
    Anyways, i wanted to know will the performance of the
    page improve if we call the database from a separate
    java rather than directly from jsp?As evnafets said, the answer is no. It may even be faster :)
    cheers,
    ram.

  • Creating simple Web Services from Plain Old Java Objects (PoJo)

    This post is with reference to a sun web page at URL - http://developers.sun.com/appserver/reference/techart/ws_mgmt.html
    It is a crisply written tutorial on creating a simple Java class and deploy the class as a JAX-WS 2.0 Web service.
    Requires -
    a) Sun Application Server - I got App Server Platform Edition 9.0_01
    b) Also requires Java_Home to JDK 1.5.0 - this was something i did even though my App Server i believe is using jdk 1.6.
    [The reason i know that is because when i removed jdk 1.6. directory from my C:\Java location, my app server asadmin commands would not be found. While i dont remember configuring the App Server to point to JDK 1.6. specifically, i am assuming the app server version i downloaded and installed auto installs it and uses it]
    I wrote up the class as described in the tutorial.
    Initially i had difficulty compiling the class, and it would error out as being unable to find the javax.jws package.
    I researched the problem a little and included the jaxws-tools.jar in the classpath and that error went away.
    According to the tutorial the presence of the @WebService annotation will tell the App Server to process it as such and also auto deploy it to the App Server.
    However while the class file is created, the autodeploy part fails completely.
    I have the entries in server.log corresponding to this javac execution stored in a separate file. Didnt know how best to attach it here.
    Please help.
    Best regards,

    Just inline the appropriate pieces of the server log.

  • Database access from Oracle Java Cloud Service application

    I have registered for Oracle Java Cloud Service for trial period. I want to deploy a Spring MVC 3.2 and Hibernate 4.0 web application.
    I created a table in the Database Cloud. I am not sure how do I access the Database Cloud Service from my application.
    Need your guidance/pointers/references that can help me establish connection from my application to the database.
    Thanks,
    Ujjwal

    Hi,
    Use JPA - see the visitors example, it uses @PersistenceUnit injection with previously weaved .class entity files.
    You can use application managed EMF's and EntityManagers with code like the following - which is not preferable to using @PersistenceContext injection on an @Stateless session EJB but...
              EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPAServletPU");
              EntityManager em = emf.createEntityManager();
              EntityTransaction transaction = null;
              try {
                   transaction = em.getTransaction();
                   transaction.begin();
                   Visitor entity = new Visitor();
                   entity.setName(name);
                   entity.setNum(num);
                   em.persist(entity);
                   transaction.commit();
                   System.out.println("Committing: " + entity);
              } catch (Exception e) {
                   e.printStackTrace();
              } finally {
                   em.close();
                   emf.close();
    Use a persistence.xml like the following
    <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="JPAServletPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
         <!--https://cloud.oracle.com/mycloud/f?p=5300:1000:259334829915901-->
    <jta-data-source>database</jta-data-source>
    <class>com.vision.cloud.jpa.Visitor</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
         <property name="eclipselink.target-database" value="Oracle10g" />
    <property name="eclipselink.ddl-generation" value="create-tables"/>
    <!-- property name="eclipselink.ddl-generation" value="drop-and-create-tables"/-->
    </properties>
    </persistence-unit>
    </persistence>
    Check out a tutorial on WebLogic JPA ORM usage here to get started as well.
    http://wiki.eclipse.org/EclipseLink/Examples/JPA/WebLogic_Web_Tutorial

  • Database Access from JSP

    I'm trying to access a SQL Server database through an ODBC connection on a JSP page and having difficulties. This is the code that I'm using:
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn = DriverManager.getConnection("jdbc:odbc:ODBCConnection", "username", "password");
    Statement stmt = conn.createStatement();
    ResultSet results = stmt.executeQuery(
    "SELECT numUserID, txtUsername, txtPassword FROM tblUsers");
    while (results.next()) {
    int DBuserid = results.getInt("numUserID");
    String DBusername = results.getString("txtUsername");
    String DBpassword = results.getString("txtPassword");
    conn.close();
    } catch (Exception exc) {                              
    out.println ("Exception \"" + exc + "\" occured....<br>");
    exc.printStackTrace();
    I've got two servers I'm testing it on. One is the IBM WebSphere 3.5 on Windows NT 4 and the other one is the Oracle 9i Server (Apache) with java support on Windows 2000. The code works fine on the Oracle server, but does not work on the WebSphere. I am getting a "java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Client unable to establish connection" exception. The problem is that I need to run this thing on the WebSphere server.
    I guess this might have something to do with the Java server differences or OS differences, but I don't know what that could be. I'm sure there's something that I'm not doing right, I just need some help figuring out what that is. I'd appreciate any help anyone can provide. Thanks.

    ODBC connection is set up the same on both servers and works with Access. In fact, I have tried to put the same code that I'm trying to use in a regular text java file, it compiled and ran on that same server. I've got a feeling I have the Websphere server setup wrong, but I don't know exactly what and how to fix it.
    Thanks.

  • Database access from Managed/Backing bean

    Hi,
    I would like to authenticate web users from a database table, I get the account details
    in the Welcome page, I wish to check if the user exists in the table (from the managed bean), how do I do this?
    Is this good practice to access the db from managed bean? If not how do I do this in model component and pass the value back and forth from managed bean?
    Thanks,
    Jai.

    Hi
    You can get all the information of logged in user from SecurityContext(you can get this either from ADFContext using ADFContext.getCurrent().getSecurityContext() or using EL expression eg. #{securityContext.userName} shows logged in user name)
    API: http://download.oracle.com/docs/cd/E15051_01/apirefs.1111/e10686/oracle/adf/share/security/SecurityContext.html#method_summary
    More details on enabling security: http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/adding_security.htm#BGBCEDDD
    Sireesha

  • Database Access from Web Center Portal Application

    Hi,
    I have a requirement to store user preferences in database. These preferences will be fetched at the time of user login and page will be rendered accordingly.
    I was just wondering should I use Entity objects/view object for DB interaction or should I go for eclipselink.
    Please guide which will be the best way keeping performance, maintenance stuff in mind.
    Thanks,
    VN

    I am sorry I missed the environment details.
    I am building oracle webcenter application using ADF framework.
    I cannot use MDS as my user preferences requirements are as follows
    1.Save a certain tab as preferred on a certain page.
    2.Bookmark a product as favorite (Product list will be displayed as dynamic content fetched from UCM)
    3.Make a certain page as home page
    I did some R&D and concluded that these features cannot be implemented without customization (please correct and guide if I am wrong)
    Now I have a custom solution where we will save user prefs in custom DB.
    Coming back to the original question - I need to do some light DB interactions and I am wondering if I can use entity /view object to fetch and update date in DB. Or this is not recommended for such a small degree of DB interaction and I should go for Eclipse link.
    Hope it gives more clarity.
    Please help.
    Thanks,
    VN

  • Access to Database Access from JDBC

    Hello,
    I have a RFC to JDBC scenario.
    The database is on a different machine to the XI, but from XI is going to map a drive to see the database.
    In the communication channel I specified the drive with the rest of the path:
    jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=Z:/TestDB.mdb
    and I get an error:
    com.sap.aii.af.ra.ms.api.DeliveryException: Database connection could not be established
    Is it possible to access an Access database that is not physically in the machine XI?
    thanks very much,

    hi silvia
    first, you need to install JDBC driver in PI to be able to connect to MS Access.
    please, see these links
    https://forums.sdn.sap.com/click.jspa?searchID=24103238&messageID=7100823
    Re: MS access o XI : External driverof access is required or not.
    Regarding File to JDBC/MS Access database
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f04ce027-934d-2a10-5a8f-fa0b1ed4d88f
    thanks
    PD:points if useful
    Rodrigo

  • Database access from iWeb

    hi all,
    Is there a way to access a database from iWeb (insert database records, update, delete, read ...)
    Thank you,
    Johnny

    Short answer : No
    Here's how you can find out :
    1. Pull down a menu and see if there's a command.
    2. Open the Inspector and check the 10 icons.
    3. Open the Media pane and see if there's a widget.
    If there's none, you have to type the code yourself.
    Here's some explanation how to use PHP in a HTML Snippet :
    http://www.wyodor.net/blog/archives/2010/07/entry_317.html
    http://www.wyodor.net/blog/archives/2011/08/entry_320.html
    And here's an explanation how to use the HTML Snippet :
    http://www.wyodor.net/blog/archives/2009/07/entry_213.html

  • Database access from WDJava

    Hi experts!!
    I am trying to implement a WD Java with two views.
    The first ones passes the selection parameters for the select statement (to acces the database) in the second one that will show the result of the select statement in table format.
    So far i've implemented the first part:
    When the user presses the 'Submit' button of the first view the following code is triggered. My question is how can i pass the data to the second view's table??? And in which method of the view??
    IWDNode node = wdContext.getChildNode("TEST",0);
    ITESTElement test = wdContext.nodeTEST().currentTESTElement();
            String  name = (String) test.getAttributeValue("NAME");
            String  surname = (String) test.getAttributeValue("SURNAME");
            InitialContext ctx;
            try {
                 ctx = new InitialContext();
               DataSource ds = (DataSource)ctx.lookup( "jdbc/SELECT_POOL");
                 Connection con = ds.getConnection();
              String SelectStmt = "select * from IR_TETS where "
                  + "where NAME = '" + name + "'" ;
                 PreparedStatement stmt = con.prepareStatement(SelectStmt);
            ResultSet resultSet = stmt.executeQuery();
    Please help!!!
    Thanx in advance!!!

    Hi,
    Create a node which contains two attributes
    Ex:
    Details  Cardianlity 0..n
       Name  String
       Age     integer
    Following code will help you to populate the context created above using the data fetched from DB
    InitialContext ctx;
           try {
                ctx = new InitialContext();
                DataSource ds = (DataSource)ctx.lookup( "jdbc/SELECT_POOL");
                Connection con = ds.getConnection();
                String SelectStmt = "select NAME,AGE from IR_TETS where "
                + "where NAME = '" + name + "'" ;
                PreparedStatement stmt = con.prepareStatement(SelectStmt);
                ResultSet resultSet = stmt.executeQuery();
                while (resultSet.next())
                     IWDNodeElement element = wdContext.nodeDetails().createElement();
                     element.setAttributeValue("Name", resultSet.getString("NAME"));
                     element.setAttributeValue("Age", resultSet.getInt("AGE"));
    wdContext.nodeDetails().addElement(element)
           }catch (Exception e) {
              // TODO: handle exception
    Now bind this node to the table
    If their exists records in db you will be able to see them
    Regards
    Ayyapparaj

  • Database access from AIR

    Hello all,
    I'm just getting started with AIR and I'm loving it! One
    thing that I can't seem to find any information about (perhaps
    because it hasn't been done...) is accessing information from a
    database without a (PHP or whatever) program on the server-side
    acting as an intermediary? I know that socket communications are
    available, are there AS / JS libraries available to do this?
    Thanks
    Allan

    You seem pretty conversant with sockets and all; just wanted
    to make sure you knew there is an embedded sqlite app within AIR.
    Don't mean to be patronizing, but if you're looking for a local
    machine solution, it's pretty cool.

  • Direct Database calls from FLEX client

    Hi all,
    is there any way to make direct database calls to a MySQL database (or any other database) from a FLEX client, rather than invoking through a service? simply, i need to remove the middle tier.
    Thanks in advance.
    SajKK

    Air only supports SQL Lite for now may be more in future.
    http://www.adobe.com/devnet/air/ajax/quickstart/sync_simple_sql_database.html
    http://www.insideria.com/2008/03/air-api-querying-a-local-datab.html
    http://ntt.cc/2008/07/08/sqlite-example-for-adobe-air-working-with-local-sql-databases-wit h-source-code.html

Maybe you are looking for