How to create database connection and how to call it using Java

Hi,
Good day! I'd like to know how I can create a db connection in JDev, then use this connection to retrieve data using a Java Class? I've seen using New Gallery > Database Connection. But I'm not sure how I can access this connection using Java and display some output from the retrieved records.
Any steps/tutorial link is appreciated.
Thanks in advance,
Rian

Hi,
If you need to access the connection in the entity object then refer http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcadvgen.htm#BABEIFAI i.e in MODEL.
But if you want to access connection in ViewController part of application then you need to do it manually.For this i am giving you my code for reference.------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.faces.context.FacesContext;
import oracle.jdbc.pool.OracleDataSource;
public class DataHandler {
String jdbcUrl = null;
String userid = null;
String password = null;
Connection conn;
public static final String CONNECTION_STRING =
FacesContext.getCurrentInstance().getExternalContext().getInitParameter("connectionString");
public static final String USER_NAME =
FacesContext.getCurrentInstance().getExternalContext().getInitParameter("userName");
public static final String PASSWORD =
FacesContext.getCurrentInstance().getExternalContext().getInitParameter("password");
public DataHandler(String jdbcUrl, String userid, String password,
boolean shouldConnect) throws SQLException {
this.jdbcUrl = jdbcUrl;
this.userid = userid;
this.password = password;
if (shouldConnect) {
connect();
public void connect() throws SQLException {
OracleDataSource ds;
ds = new OracleDataSource();
ds.setURL(jdbcUrl);
conn = ds.getConnection(userid, password);
public Connection getConnection() {
return conn;
public ResultSet executeQuery(String sql) throws SQLException {
Statement s = conn.createStatement();
return s.executeQuery(sql);
public void closeConnection() throws SQLException {
if (!conn.isClosed()) {
conn.close();
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Similar Messages

  • How we create custom infotype and how to configure with its subtypes.

    hai abap-hr gurus,
    how to create custom infotype and how to configure with its subtypes. when i am creating infotypes i am not getting how to configure subtypes.
    plz help me for this with an example code.
    thanks..
    kiran kumar

    Hi Kiran,
        Please fallow the below steps to create the custom infotype. If you have any quires let me know.
    For Creation of Infotype first Go to Transaction PM01, Enter the custom Infotype number which you want to create, it should be a 4 digit number and have to start with 9xxx.
    then select the `Employee Infotype' radio button
    after that select the `PS Structure Infotype'
    then click on Create… A separate table maintenance window appears
    then Create a PS structure with all the fields you want on the infotype
    Save and Activate the PS structure
    now Go back to the initial screen of PM01
    Click on `All' push button. It takes a few moments
    Click on `Technical Characteristics’. Infotype list screen appears
    Click on `Change'(pencil) button
    Now select your Infotype and click on `Detail' (magnifying glass) button
    Give `T591A' as subtype table & also Give `T591S' as subtype txt tab
    Give your subtype field as subtype field & Save and come back to PM01 initial screen
    Click on `Infotype Characteristics' … Infotype list screen appears
    Click on `Change' (pencil) button & on New Entries
    and then Enter your Infotype number and short text Here we have to set different Infotype Characteristics as per the requirement. (Better open another session with some standard Infotype's infotype characteristics screen and use as the reference
    to fill yours). Now save ur entries
    Now the Infotype is created and ready to use.
    If you want to change the layout of the Infotype as per your
    requirement…
    In the PM01 initial screen…Select `Screen' radio button and give
    2000 as the screen name, then click on edit.
    In the next screen.. Select `Layout Editor' and click `Change'.
    Screen default layout appears…here you can design/modify the
    screen..change the attributes of the fields..etc.
    Save and activate. (Don't forget to `Activate at every level)
    Regards,
    Ramakrishna kotha.

  • Can any 1 tell me how to create budget journal and how to enter journal ?

    hi all+
    Can any one tell me how to create budget journal and how to enter journal against that budget ?+
    Regards+
    Yasir+

    http://download.oracle.com/docs/cd/A60725_05/html/comnls/us/gl/budjrnl.htm#index-Budget-journals-Entering--0
    Enter budget journals to maintain an audit trail for your budget balances. You can use budget rules to calculate budget journal amounts automatically.
    When you post budget journals, the journal amounts update existing budget balances. You can review and change your budget journals before posting them.
    Attention: When you use budget rules in Journal Mode, General Ledger calculates the appropriate debit or credit needed to achieve the balance you enter for the account type.
    Prerequisites
    1. Define a budget
    2.Open one or more years for your budget
    3.Define a budget organization
    4. Assign the "Entered" budget entry type to the accounts for which you want to enter budget journals
    To enter budget journals for a single account:
    1. Navigate to the Enter Budget Journals window.
    2. Specify the Budget Organization for the account to which you want to budget. If the budget organization is password-protected, you must enter the password before you can enter budget journals.
    3. Enter the Budget you want to update. You cannot use a budget that is frozen.
    4. Enter the range of Accounting Periods to which you want to budget.
    5. Enter the Currency of the budget amounts you are entering. The accounts must be assigned to the budget organization for this currency.
    6. Choose Journal Mode from the region poplist to enter budget amounts in a journal format.
    You can also use Single Row Mode or Worksheet Mode to enter budget journal amounts. However, you can only generate budget journals from these entry modes when you use the Enter Budget Journals window.
    Additional Information: When you use Journal Mode, Balance Type is a display-only field. It displays Budget when you are entering budget journals. In the Enter Journals window, this field displays Actual when you are entering actual journals.
    7. Enter or query the Account to which you want to budget. You can also switch to Worksheet Mode to easily query accounts, then return to Journal Mode to enter budget journals.
    8. Enter a Debit or Credit amount for each period. Do not enter journal amounts if you want to use budget rules to calculate and distribute budget amounts.
    9. Choose Create Journals to create a budget journal batch. If you are using budgetary control, you specify a funds action when you create the batch.

  • How to create process chains,and how to use process like and or xor

    Hi,
    How to create process chains,and how to use process like and or xor.
    can any one please give me a example in each.
    Thanks,
    cheta.

    Hi Cheta,
    Here is step by step procedure to create process chains
    Process chain is nothing but executing a process ..(or) loading the data any process we can do in background.. that means.. automatically we can execute our process based on Time or any event..
    Creating Process Chains
    Prerequisites
    If you want to include a load process in the process chain, you need to have already created an InfoPackage.
    You cannot load flat file data from a client workstation in the background. For this reason, you have stored your data on an application server.
    Creating Process Chains
    You have the option of creating a process chain in the process chain maintenance screen directly or by using a maintenance dialog for a process:
    Creating a Process Chain Directly in the Process Chain Maintenance Screen
    You are in the BW Administrator Workbench.
    1. Click on the Process Chain Maintenance icon in the AWB toolbar.
    The Process Chain Selection dialog window appears.
    2. Choose Create.
    3. Enter the technical name and a description of the chain, and confirm your entry.
    The Add Start Process dialog window appears.
    4. Create a variant for a start process.
    1. a. On the Maintain Start Process screen, choose whether you want to schedule the chain directly or whether you want to start it using a metachain.
    2. b. If you choose to schedule the chain directly, enter the start date value for the chain under Change Selections and save your entries.
    The Maintain Start Process screen appears again.
    3. c. Save your entries, return to the previous screen and confirm your entries in the Add Start Process dialog window.
    You are taken to the Plan View of the process chain maintenance screen.
    In the left-hand area of the screen, a navigation area is displayed. In the right-hand area of the screen, the process chain is displayed.
    5. Use the drag-and-drop function to add the relevant processes into your process chain.
    You use the Process Types function to select the processes. This sorts the process types according to different categories. You can also call up InfoPackages and processes for the data target from the separate InfoSources and Data Targets navigation trees.
    Hope this helps
    Regards
    Karthik

  • How to create Database, table , and apply triiger on oracle10g lite ?

    Hello All,
    I want to use oracle 10g lite , i just download oracle 10g lite from oracle site and just install on my system, i have no any knowledge how to create database, how to create tables and how to apply triggers on tables. I want to access this database using JDBC.
    plzzzzzzzzzzzzzzzzzz help me...............
    Thanks in advance
    Pankaj

    are you trying to use oracle lite just as a database? it is normally used as part of a data synchronisation from a server, replicating snapshots to create the database and tables on the client.
    PL/SQL format triggers are not supported in the oracle lite client. Java stored procedures are, but you would need to build the table interactions

  • How to create a connection pooling in Netbeans 6.0 using the oracle driver

    hi all,
    I am using Netbeans 6.0. Apache Tomcat 6.0.14 server, oracle 9i.
    I tried to create a connection pooling using tomcat web server.
    I have included the following code in context.xml and web.xml.
    CONTEXT.XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <Context path="/network1">
    <Resource name="jdbc/myoracle"
    auth="Container"
    type="javax.sql.DataSource"
    username="scott"
    password="tiger"
    factory="BasicDataSourceFactory"
    driverClassName="oracle.jdbc.OracleDriver"
    url="jdbc:odbc:thin:@127.0.0.1:1521:mydb"
    maxActive="20"
    maxIdle="10"
    maxwait="-1"/>
    </Context>
    WEB.XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <session-config>
    <session-timeout>
    30
    </session-timeout>
    </session-config>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <resource-ref>
    <description>Oracle Datasource example</description>
    <res-ref-name>jdbc/myoracle</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    </web-app>
    After that i have included the following JDBC driver's jar files in the $Catalina_Home/lib folder.
    classes 111.jar,
    classes 111_g.jar
    classes12.jar
    classes 12_g.jar
    classes12dms.jar
    classes12dms_g.jar
    nls_charset11.jar
    nls_charset12.jar
    ocrs12.jar
    ojdbc14.jar
    ojdbc14_g.jar
    Then i stop the tomcat web server and start it again.
    In jsp page i have included the following code:
    Context ctx=new InitialContext();
    Context envctx=(Context)ctx.lookup("java:comp:env");
    DataSource ds=(DataSource)envctx.lookup("jdbc/myoracle");
    Connection con=ds.getConnection(); ----->(In this line an error occured that Connection class cannot be found.)
    please help me how to create a connection pooling and rectify the error in conneciton.
    Thanks in advance

    Please refer
    http://www.netbeans.org/kb/60/web/customer-book.html

  • How to create new user and How can i assign end user roles

    Hi,
    I am new to SAP, please explain how to create end users and their roles
    Thanks
    ravi

    Hi,
    Roles are decided by IT managers. Suppose if Persons who are working in shopfloor or production side
    give authorization to Production order create , change and Confirm like that etc
    1. In role maintenance (transaction PFCG), choose the Authorizations tab page.
    2. To change the authorization data for the transactions assigned to the role, choose Change Authorization Data or Expert Mode for Profile Generation. Otherwise, a dialog box appears in expert mode (see Regenerating an Authorization Profile After Changes).
    Please take telp from Basis person also refer this link,
    http://help.sap.com/saphelp_46c/helpdata/EN/52/6714a9439b11d1896f0000e8322d00/frameset.htm
    Thanks

  • How to create database connection using DB2Driver in JDeveloper 10.1.2.1.0?

    I am trying to create a JDeveloper/Data Connection using com.oracle.ias.jdbc.db2.DB2Driver. The driver is registered from a User Libraries: DataDirect JDBC. I have the following class path for the library:
    E:\DataDirect\3.4\lib\YMdb2.jar;E:\DataDirect\3.4\lib\YMbase.jar;E:\DataDirect\3.4\lib\YMutil.jar
    I have no trouble configuring the connection but when I test it and I got ‘No suitable driver Vendor code 0’. What’s wrong? I have successfully created several database connections using Oracle thin driver. This is first time I am using a third party driver. Has any one successfully create a database connection using the com.oracle.ias.jdbc.db2.DB2Driver?

    Hi
    Since the error points to the unavailability of the driver class,can you double check your library claspath entries again.
    I just tried a DB2 connection using the following properties and the connection went through fine:
    Driver class name: com.oracle.ias.jdbc.db2.DB2Driver
    URL: jdbc:merant:db2://<host_name>:50000;DatabaseName=SAMPLE
    Thanks
    Prasanth

  • How to create  database connection in JDev

    Dear Sir,
    I am not able to create a connection to the Oracle9i database in JDeveloper.Plz guide me.
    Thanx
    Aradhana Jain

    Please post this in the JDeveloper forums for an appropriate response: JDeveloper and ADF
    OTN

  • Material on how to create custom idoc and how to distribute it

    hi friends,
    can anyone suggest me some good material on custom idoc and how to trigger them.
    please let me know.
    regards,
    roberts.k

    Please check this link.
    http://help.sap.com/saphelp_46c/helpdata/en/dc/6b835943d711d1893e0000e8323c4f/content.htm
    Cheers,
    Ramki.

  • How to ZIP the files and folders/sub folder files using java

    HI All,
    I'm New to this Forum, Could anybody tell me how to zip the files and folders/sub folders using java. For example I have a folder with the name testfolder and side that folder I have some files and some sub folders inside subfolders I have some other files. I need to ZIP the files and folders as they are in same hierarchy.
    Any pointers or help wolud be appritiated.
    Thanks,
    Rajeshbabu V

    [http://www.devx.com/tips/Tip/14049]

  • How to Create a connection and User Seesion and Authentificate Session

    Hi
        I would like that someone provide my the code to set a connection with MDM through the MDM Java APIS SP6 Patch2. I need to connect with the repository, and authentificate the User and the Password. Furthermore I would need the code to pick up events like add record and modified record. When a record is added or modified is neccesary to pick up the value of a lookup field in the main table to check that this value is a specific value in order to syndicate this record. That´s possible that someone provide this code to me.
    thanks in advance.  If the reply is useful there will be rewards Points.

    Hi,
    Check this out
    ConnectionAccessor simpleConnection=null;
    RepositorySchema repSchema=null;
    RepositoryIdentifier repIdentifier=null;
    DBMSType dbmsType = DBMSType.MS_SQL;
    String session=null;
    String connection = "MDM_SERVER_PROD";
    String repository  = "TEST_REP";
    simpleConnection = SimpleConnectionFactory.getInstance(connection);
    repIdentifier = new RepositoryIdentifier(repository, connection, dbmsType);
    RegionProperties dataRegion = getRegion();
    CreateUserSessionCommand createUSesCmd = new CreateUserSessionCommand(simpleConnection);
    createUSesCmd.setDataRegion(dataRegion);
    createUSesCmd.setRepositoryIdentifier(repIdentifier);
    createUSesCmd.execute();
    session = createUSesCmd.getUserSession();
    AuthenticateUserSessionCommand authUSesCmd = new AuthenticateUserSessionCommand(simpleConnection);
    authUSesCmd.setSession(session);
    authUSesCmd.setUserName("Admin");
    authUSesCmd.setUserPassword("pass123");
    authUSesCmd.execute();
    GetRepositorySchemaCommand getRepSchCmd = new GetRepositorySchemaCommand(simpleConnection);
    getRepSchCmd.setSession(session);
    getRepSchCmd.execute();
    Just put all the execute statements within try catch block
    Regards,
    Jitesh Talreja

  • How to create a variable, and how to use the same across all the reports?

    Hi,
    Is there any possibility of creating a variable at once and making use of that across in all the Crystal Reports?
    Thanks In advance for your time and solution.

    MohanMRK,
    can you describe how you get the value for this variable?
    is it calculated on one report and then you want to pass it to a 2nd report? if that's the case, what you can do is have the reports linked via an opendocument link and pass the value to the 2nd report as a parameter. the value / parameter is only shared when you press the opendocument hyperlink.
    please see the sdk library [here |http://www.sdn.sap.com/irj/boc/sdklibrary]and scroll down to the opendocument section near the bottom.
    if you are just trying to find a way to share a calculation across reports look into creating a Custom Function which can be added to your repository. please note that this will not pass a calculated value across 2 or more reports, but will just have a shared method of making the calculation.
    as Abhilash mentioned before, there's no way to use an actual Variable across 2 separate reports without them being a main report and subreport(s). in that case you'll want to look into Shared Variables.
    cheers,
    jamie

  • How to create a Ticker and How to populate value in it ??

    Hi Team,
    Can any one help me out to create a simple ticker ..
    Can you take me through the steps .... I tried some which are not working ..
    I have added a form where I have a submit button with a ticker and other fields, and the output is a table with two fields ... where both the fields has only  one value ..
    I want these values to be displayed in Ticker box ... How can I do it ??
    Regards,
    chan

    Hi Prachi,
    Thanx for your reply.
    Let me explain my scenario. It is very simple .. I have a BW Query where the put put is Netsales till yesterday. The output is a 1 row 1 column value which should be displayed in a ticker with respective date (date single value ie till yesterday).
    Query is very simple. As you said It can be used only in a form.
    In a form I have added a ticker. In style -> condition -> @Net_Sales==true where <b>@Net_sales</b> is the NetSales value string. It is not gining any error but, output is not displayed where as If I use a text box to display the same value is displayed.
    I know that I m missing some settings, can u guide me to do that properly.
    Regards,
    Chan

  • How to create own SplitPaneDivider and how to use it

    Hi,
    I'm trying to create my own SplitPaneDivider and set it for one of my SplitPanes by doing:
    JSplitPane splitterPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,listTablePanel, editorPanel);
    splitterPanel.setOneTouchExpandable(true);
    splitterPanel.setUI(new MySplitPaneUI());
    splitterPanel.updateUI();
    splitterPanel.setBorder(BorderFactory.createEmptyBorder());
    splitterPanel.setDividerSize(8);
    When I do this, I see no difference when I change it to MetalSplitPaneUI
    Can anyone tell me what I'm doing wrong.
    Thanks in advance
    Hugo

    Let me know if any clarification is needed
    Kudos are always welcome if you got solution to some extent.
    I need my difficulties because they are necessary to enjoy my success.
    --Ranjeet
    Attachments:
    VI.vi ‏13 KB

Maybe you are looking for

  • Unable to enter multiple Schedule lines for BOM material in Sales Order

    Hi All, We have a Sales Order where in which we cannot add additional schedule lines for BOM material. The schedule lines are greyed out, user was able to add schedule lines earlier. I have checked all assignments in VOV6, VOV7 and everything seems t

  • Lync 2013 (part of Office 365 Click to run package) Crashes at startup.

    Faulting application name: lync.exe, version: 15.0.4675.1000, time stamp: 0x54629b81 Faulting module name: KERNELBASE.dll, version: 6.1.7601.22616, time stamp: 0x5315adc5 Exception code: 0xe06d7363 Fault offset: 0x0000c44d Faulting process id: 0x1848

  • Weather Icon

    I really would like to use the weather feature but I can't change it to reflect my city's weather, is there anyway to change it?

  • Issue in 9.2.0.6 to 10.2.0.4 upgrade

    Hello All, We are in process of upgrading the database [ 9.2.0.6 to 10.2.0.4 ] and application [ 11i CU1 to CU2 ]. We have completed the Database upgrade and all the dba_registry components are VALID. But still there are lots of INVALID objects in th

  • Could not order iphoto book due to error not enough photos are filled

    I am not able to buy the iphoto book , as there is a message that there is no enough photos in the frame , though every page as all the photos filled up . Please help