Connect Oracle with Java

I want to access oracle database from my java program which is written on Java Swing. e.g suppose my program shows a screen containing a "Name" field and a button "Submit". When i will enter a name and press the submit button the name will be stored into a table . How can i do that?
I use Oracle 8i for database and JDK 1.7.0 for Java environment.

Hi,
Use the below code to connect to the Oracle DB and do the required Operation with the custom parameters for IP etc.,.
public static void updatEmp(int empNo, String eName){
          System.out.println("Oracle Connect Example.");
          Connection conn = null;
          String ipAddress ="";
          //Spedify your IP address
          String tnsName = "";
          // Specify your tns name eg. "orcl"
          String url = "jdbc:oracle:thin:@"+ipAddress+":1521:"+tnsName;
          String driver = "oracle.jdbc.driver.OracleDriver";
          String userName = "scott";
          String password = "tiger";
          try {
          Class.forName(driver).newInstance();
          conn = DriverManager.getConnection(url,userName,password);
          System.out.println("Connected to the database");
          conn.setAutoCommit(false);
          PreparedStatement preStmt = conn.prepareStatement("update emp set ename = ? where empno =?");
          preStmt.setInt(2, empNo);
          preStmt.setString(1,eName);
          preStmt.executeUpdate();
          Statement st = conn.createStatement();
                    // For insertion to oracle
          int i = st.executeUpdate("insert into emp (empno,ename) values("+empno+",'"+ename+"')");
          System.out.println("No. of rows updated = "+i);
                    //For Selection from oracle
          /* ResultSet res = st.executeQuery("SELECT empno,ename FROM EMP ");
          while (res.next()){
               System.out.println("Number of column:"+res.getInt(1));
               System.out.println("Number of column:"+res.getString(2));
               conn.rollback(); */
               // For Updation to oracle
          /*int i = st.executeUpdate("update emp set ename='Hamlet' where empno=7369");
          System.out.println("No. of rows updated = "+i);*/          
          conn.close();
          System.out.println("Disconnected from database");
          } catch (Exception e) {
          e.printStackTrace();
Note:
Have to include the ojdbc14-10.2.0.2.0.jar in your java environment, which is the driver for Java to connect to oracle. If it is in Eclipse include using External jar files. If the java environment is Servers put the jar file in your lib folder under Web-INF folder..:-)
Thanks
Edited by: Ramesh_R on Aug 26, 2009 8:53 PM

Similar Messages

  • Connect Oracle with AS400

    Iam new in this , what I need, for connect Oracle with AS400...? someone Can Help me please.....
    Thanks!!!

    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/integrat.htm#sthref3364

  • How connect Oracle with AS400?

    Hi!
    I don´t know how i can connect oracle with AS400 , what I need for make the connection?

    Hi,
    You have 3 options:
    - Oracle Transparant Gateway for DRDA
    This product is available for Windows, Linux, AIX, HP-UX PA-RISC and Solaris SPARC
    It uses the IBM DRDA protocol (over TCP/IP) to establish a connection with DB2400
    - Oracle Transparant Gateway for DB2/400
    This product needs to be installed on the AS/400
    - Generic Connectivity (aka HSODBC)
    This is a default Oracle Database feature that is available for Windows, Linux x86,
         AIX, HP-UX PA RISC and Solaris Sparc.
         In addition it requires a suitable ODBC-Driver (32-bit) that is able to connect to
         DB2/400
    The gateways require additional license from Oracle, while HSODBC requires additional license for a third party ODBC vendor. Furthermore do gateways support the two phase commit protocol and calling DB2/400 stored procedures.
    Regards,
    Ed
    DRDA over TCP/IP
    Message was edited by:
    ebangma

  • Connection refused with java, but not javaw

    I have a ServerSocket based program...listening on a port. It is really a very simple program. And I can run it with javaw. Then I can use another problem, for example, telnet to connect to that port, just to prove I can connect to that port. Everything is fine.
    Now if I run the exactly the same ServerSocket program with java, then I got the connection refused error.
    It is weird.
    Do you know why? Do you know a good socket troubleshooting tool on Windows? I am afraid of the viruses, so I haven't downloaded any free tools yet.

    You're right.
    The Norton personal firewall does not handle localhost to localhost correctly. I do all the tests on the same machine. The netstat -an shows the port is listening in either case. But now I know the firewall blocks one of them silently. No rule prompt was triggered. Worse, no logging produced for that particular access.
    Thanks. You've been very helpful.

  • How to connect oracle with ms access database

    Dear
    We are on release r12, right now we have requirement to connect oracle database with ms access to get some information. We have found gateway(Heterogeneous services) using ODBC, but at the database side where is installed oracle r12 there is no installed ms access software becuse of linux operating system, so how could it will connect ms access because without installing ms-access we are unable to find ms ODBC gateway in ODBC driver under the control panel.
    Can any body guide me how could achieve this
    Edited by: oracle0282 on Sep 21, 2011 12:47 AM

    If I understand you correctly you want to access Oracle on Linux from MS-Access (possible on Windows only). You need neither a gateway nor Heterogeneous Services, but an Oracle client including ODBC driver (Instant client with ODBC driver is enough) on the Windows machine.
    Configure the ODBC driver with the connect informations to the Oracle server.
    Werner

  • Error in Remote Connect Oracle with MTS Mode

    I've configed my database to run MTS.
    My db is 8.1.5 with x86 Unix SunOS 5.7
    If I connect db through local area network, I can connect it with MTS mode.
    But if I try to connect db from a remote site, I can't connect and the following error shown :
    ERROR:
    ORA-12545: Connect failed because target host or object does not exist
    By adding a clause (SERVER = DEDICATED) in my remote client's tnsnames.ora
    I can connect it.
    Rgds,
    Edward
    The following is my configuration.
    init.ora :
    mts_dispatchers = "(PROTOCOL=TCP)(DISP=3)"
    mts_dispatchers = "(PROTOCOL=TCP)(PRE=oracle.aurora.server.SGiopServer)"
    mts_servers = 1
    mts_max_servers = 40
    mts_max_dispatchers = 4
    listener.ora :
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = QQQQdb)(PORT = 1521))
    (DESCRIPTION =
    (PROTOCOL_STACK =
    (PRESENTATION = GIOP)
    (SESSION = RAW)
    (ADDRESS = (PROTOCOL = TCP)(HOST = QQQQdb)(PORT = 2481))
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = /u01/app/oracle/product/8.1.5)
    (PROGRAM = extproc)
    (SID_DESC =
    (GLOBAL_DBNAME = QQQQdb.net)
    (ORACLE_HOME = /u01/app/oracle/product/8.1.5)
    (SID_NAME = QQQQdb)
    tnsnames.ora :
    QQQQDB =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = QQQQdb)(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME = QQQQdb.net)
    EXTPROC_CONNECTION_DATA =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    (CONNECT_DATA =
    (SID = PLSExtProc)
    (PRESENTATION = RO)
    null

    I have run into the same problem using oracle 8.1.6.1 with redhat 6.2..
    I have found out that only when I specify host ip in the mts_dispatchers the mts will work correctly..(specifying host domain name is no use)
    Here is a sample of the configuration, hope that helps..
    mts_dispatchers = "(address=(protocol=tcp)(host=192.168.0.1))(dispatchers=4)"

  • How to connect Oracle with Jsp?

    Hi,
    I am student and I am trying to use Jsp to connect oracle. Do you have any sample to show how to do it?
    Thanks a lot.
    Amy

    In JSP, you connect to the Oracle in a same way as you would do it in any Java application, using JDBC. Please refer to Java Tutorial -> JDBC on sun site and you will get easy and straight forward concepts.

  • Null connection context with java wrapped wwsec_api

    How can I specify my OID connection information when using the PL/SQL wwsec_api with java wrappers?
    I am getting a null connection context, and I assume that it is looking for the directory connection information (OID host,port,user,password).
    Is this somehow specified in the .properties file?
    The java was created with Jpublisher per the Jdeveloper help instructions. Following is a code snippet using the java classes created.
    String userName = "username";
    WwsecApi anWwsecApi = new WwsecApi();
    WwsecApiRowtypeSql3 userInfo = (WwsecApiRowtypeSql3)anWwsecApi.personInfo(userName);
    if (userInfo.getEmpno() != null)
    out.print("Employee Number" + userInfo.getEmpno());
    else
    out.print("null");

    -- Set the session context for a lightweight user as follows in your java code before executing the API call.
    -- portal.wwctx_api.set_context(p_user_name => 'portal',p_password => 'password1',p_company => 'simplerewards');
    portal.wwctx_api_private.set_context (p_user_name => 'portal');

  • Connecting oracle with php

    hi all,
    i am using Xammp 1.7.4, PHP version 5.3.5, apache 2.2, and oracle 11g. actually i know how to connect MySql using php, but now i am trying to connect oracle using php. Can any 1 tell me the clear cut steps to do the same ?

    You need to add the right oci8 DLL or .so to php.ini and make sure it has access to Oracle client libraries. These Oracle libraries are from an Oracle Home or Oracle Instant Client.
    Without knowing your platform and whether the Oracle DB is on the same machine as Xampp the best place to start is to look at
    http://www.oracle.com/technetwork/articles/technote-php-instant-084410.html

  • How to connect  oracle with c++

    i wanted to know that how should i connect oracle to c++.
    kindly list me the commands which i need to write to access database fro oracle.
    thanks ...

    If you're attempting to use the ODBC API directly, have you downloaded the ODBC SDK from Microsoft? That will include some sample code, which is a great starting point. So far as I'm aware, you shouldn't need to configure anything in Borland C++ that you don't have to configure in any other C++ compiler to use ODBC.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Connection hanging with java

    Hello
    we apply some simple Connection pool mechanism from our java code to Oracle
    8.1.6. Due to some reason, oracle connections get hanging after a while. So
    far I have not found out why :-(. The result is that whatever command they
    are running at that moment gets blocked. This may be something so simple as
    Connection.createStatement(). Result: my thread is blocked, the program is
    blocked. Parts of it I solved by doing a test before delivering a connection
    in a separate thread that gets a timeout. Not really elegant :-(. First,
    when the connection gets corrupted in the code that uses it, I have no
    access. And secondly, when the thread gets timed out, and the pool creates a
    new connection, I still have this connection hanging ...
    So, I hope that someone has some useful tips how should handle hanging
    connections, and properly clean them. Meanwhile I will try to find the
    reason of the hanging as well (maybe v$session or v$open_cursor has a clue).
    Regards

    You're right.
    The Norton personal firewall does not handle localhost to localhost correctly. I do all the tests on the same machine. The netstat -an shows the port is listening in either case. But now I know the firewall blocks one of them silently. No rule prompt was triggered. Worse, no logging produced for that particular access.
    Thanks. You've been very helpful.

  • SOAP SSL error when connecting in with java

    Hi,
    We are trying to make a simple application that makes requests to the CCM via the AXL SOAP interface to get personal address book information. When we do the request it errors out with a SSL handshake problem, I have pasted some of the exact error output below: Any help or ideas would be appreciated !!!
    at java.lang.Thread.run(Unknown Source)
    Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_
    failure
    at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
    at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Un
    known Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Sou
    rce)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Sou
    rce)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
    (Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown S
    ource)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unk
    nown Source)
    Full logs attached, I have imported the CCM cert into the Java keystore and still no luck. The only way I can get this to work by testing is to have CCM in VM and web deployed on actual physical machine and that's only for a single user dev. environment.
    Rob

    By default, the ssl certificate from the ccm is untrusted - so you get a verification error. There are two ways to work around this.. one is importing the certificate to the trusted store (google it), the other is writing your code so that it automatically accepts untrusted certs.
    For the latter, you could have a method like this (which I stole from the axlsql application)
    public void init() throws InitializationException
    X509TrustManager xtm = new MyTrustManager();
    TrustManager[] mytm = { xtm };
    SSLContext ctx;
    try
    ctx = SSLContext.getInstance("SSL");
    ctx.init(null, mytm, null);
    SSLSocketFactory sf = ctx.getSocketFactory();
    HttpsURLConnection.setDefaultSSLSocketFactory(sf);
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
    public boolean verify(String hostname, SSLSession session)
    return true;
    catch (NoSuchAlgorithmException ex)
    throw new InitializationException("SSL Algorithm not found: " + ex.getMessage());
    catch (KeyManagementException ex)
    throw new InitializationException("Key management exception: " + ex.getMessage());

  • How do I resolve connection error with Java API listener?

    I have created a listener using the new Java API (see How do I implement a listener using new MDM Java API? for background). When I run it, I get this error message
    Mar 19, 2008 3:57:58 PM com.sap.mdm.internal.net.ConnectionImpl finalize
    INFO: Disconnect was not called. Cleaning up connection in finalize.
    This message is triggered whenever I generate a data event that I would otherwise expect to be captured and handled by the listener. I have tried a number of things, including setting the connection to NO_TIMEOUT and trying SimpleConnection versus ConnectionPool, but always with the same result.
    Here is some sample code for the listener:
    public class DataListenerImpl implements DataListener {
         public void recordAdded(RecordEvent evt) {          
              System.out.println("===> Record Added Event");
              System.out.println(evt.getServerName());
         public void recordCheckedIn(RecordEvent evt) {
              System.out.println("===> Record Checked In Event");
              System.out.println(evt.getServerName());          
         public void recordCheckedOut(RecordEvent evt) {
              System.out.println("===> Record Checked Out Event");
              System.out.println(evt.getServerName());               
         public void recordModified(RecordEvent evt) {
              System.out.println("===> Record Modified Event");
              System.out.println(evt.getServerName());
    And here is the code for the Event Dispatcher:
    public void execute(Repository repository) {
         DataListener listener = new DataListenerImpl();
         try {
              EventDispatcherManager edm = EventDispatcherManager.getInstance();
              EventDispatcher ed = edm.getEventDispatcher(repository.getServer().getName());
              ed.addListener(listener);
              ed.registerDataNotifications(SystemProperties.getUserName(), SystemProperties.getPassword(),
                        repository.getIdentifier(), repository.getLoginRegion());
              ed.registerRepositoryNotifications(SystemProperties.getUserName(), SystemProperties.getPassword(),
                        repository.getIdentifier());
              ed.registerGlobalNotifications();
              while (true) {
                   Thread.yield();
                   try {
                        Thread.sleep(1500);
                   } catch (InterruptedException ex) {
                        System.out.println("Interrupted Exception: " + ex.getMessage());
         } catch (ConnectionException e) {
              e.printStackTrace();
         } catch (CommandException e) {
              e.printStackTrace();
    Has anyone else encountered this message? Could it be related to a TCP configuration on the server? Or is this a bug in the Java API?
    As I mentioned in the forum posting linked to above, I have not encountered this problem with the MDM4J API.
    Any help is greatly appreciated.

    I resolved it. We are switching over to SP6, Patch 1 and the listener code works fine with this version of the Java API.
    Just one thing to note, though: make sure that you register data notifications through MetadataManager in your initialization code:
    metadataManager.registerDataNotifications(userSessionContext, repositoryPassword);
    For information on the changes to the SP6 Java API, especially with regard to connecting to MDM with the UserSessionContext, please review Richard LeBlanc's [presentation|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/20073a91-3e8b-2a10-52ae-e1b4a10add1c].

  • Can I connect Oracle with SQL-Server

    Hi,
    Is it possible to do Oracle hetrogeneous connectivity with Sql Server??
    Regards,
    Darshan

    Hi,
    I wanted to know whether Transparent Gateway for SQL Server is installed or not?
    In my $ORACLE_HOME I found following folders
    tg4ifmx, tg4ingr, tg4sybs, tg4tera.
    =========================
    If I want to install Gateway for SQL Server, From where do I install it???
    JAI HIND
    Darshan

  • How to Connect Oracle with Crystal Reports

    Hi Everyone,
    I am new to Crystal Report,
    Just tell me how to connect Crystal Report thro' Oracle 9i or 10g Forms
    With regards,
    Krishnan

    You may want to use ODBC for the connectivity.

Maybe you are looking for

  • Connecting powerbook g4 to samsung lcd le32 r7

    does anyone know how to connect a powerbook g4 to a samsung lcd le32 r7. At the moment im using a dvi to vga adapter. The mac can see the tv but the tv cannot see the mac. i have tried different modes on the tv and different screen resolutions but no

  • What is going on here

    I have a project that I am working on. It's 1920 x 1080 60i footage and stills, in a 1920 x 1080 AIC project. I have about 5 or 6 sequences in one project and 2 in another project that I want to use. 1. I create a new sequence called final. 2. I add

  • Alternating blinking Apple icon and low battery indicator

    My nano has been displaying an alternating blinking Apple icon and a low battery indicator. I have tried to reset it, but it doesn't change. I have connected it via USB to my computer for several hours, and I have connected it to an AC charger for a

  • GI Issue !!

    HI 10 ea of material X issued to a cost center 1001. Next day the guy comes and wants to return 2 ea of X back to store. I try to do 202 in MB1A for same material X from cost center 1001 then I get this error "Update control of movement type is incor

  • Where can I find and download OS X Lion?

    I would like to upgrade to OS X Lion to have iCloud available but I can't find it to download it. Anyone know where I can find it?