Access oracle database from different classes in desktop / standalone app.

I am a bit confused as to what way to go. I am building a desktop application that needs to access an oracle database. I have done this in the past using code similar to the following:
        try {             DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());             Connection conn = DriverManager.getConnection(                     "jdbc:oracle:thin:@111.111.111.111:oracledb",                     "username", "password" );             // Create a Statement             Statement stmt = conn.createStatement();             ResultSet rs = stmt.executeQuery(                     "select ... from ...");             while (rs.next()) {                 ReportNumberCombo.addItem(rs.getString(1));             } // end of rs while             conn.close();         } //  end of try         catch( Exception e ) {             e.printStackTrace();         }
The problem I would like to resolve is that I have this code all over the place in my application. I would like to have it in one objects method that i can call from other classes. I can't easily see how to do this, or maybe at this point I'm just too confused.
I want to be able to change this connection info from a properties file which I have already done, not sure if this bit of information would change the answer to my question. I was also looking at the DataSource api, this looks like it is close to what I should use, what are your thoughts?
I would also like to if JNDI is only for web applications or would be appropriate for a desktop app.
Thank you for your help, I realize this is all over the place but I really need these topics cleared up!

I have tried exactly that and am getting an error which let me to believe it couldn't be done that way. Here is my code and error message:
public class readPropsFile {
    String getURL() throws IOException {
        // default values for properties file
        String Family = "Family:jdbc" + ":oracle:" + "thin:@";
        String Server = "Server:111.111.111.111";
        String Port = "Port:1521";
        String Host = "Host:oradb";
        String Username = "Username:username";
        String Password = "Password:password";
        try {          
            new BufferedReader(new FileReader("C:\\data\\Properties.txt"));
        } catch (FileNotFoundException filenotfound) {
            System.out.println("Error: " + filenotfound.getMessage());
            // displays to console if file DOES NOT exist
            System.out.println("The file DOES NOT exist, now creating...");
            FileWriter fileObject = null;
            fileObject = new FileWriter("c:\\data\\Properties.txt");
            BufferedWriter out = new BufferedWriter(fileObject);
            // writes to output as simple text.
            out.write(Family);
            out.newLine();
            out.write(Server);
            out.newLine();
            out.write(Port);
            out.newLine();
            out.write(Host);
            out.newLine();
            out.write(Username);
            out.newLine();
            out.write(Password);
            out.newLine();
            out.close();
        // displays to console if file exists
        System.out.println("The file exists, or was created sucessfully");
//      creates the properties object, assigns text file.
        Properties props = new Properties();
        FileInputStream in = new FileInputStream("c:\\data\\Properties.txt");
        props.load(in);
        Family = props.getProperty("Family");
        Server = props.getProperty("Server");
        Port = props.getProperty("Port");
        Host = props.getProperty("Host");
        Username = props.getProperty("Username");
        Password = props.getProperty("Password");
//      prints properties to a file for troubleshooting
        PrintStream s = new PrintStream("c:\\data\\list.txt");
        props.list(s);
        in.close();
        String URL = "\"" + Family + Server + ":" + Port + ":" + Host + "\"" +
                "," + "\"" + Username + "\"" + "," + "\"" + Password + "\"";
        System.out.println("This is the URL:" + URL);
        return URL;
}And here is where I try to call the method:
public class connWithProps1 {
    public static void main(String[] args) {
        readPropsFile callProps = new readPropsFile();
        try {
            callProps.getURL();
            String url = callProps.getURL(); // not needed
            System.out.println("The URL (in connWithProps1) is: " + csoProps.getURL());
            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
            Connection conn = DriverManager.getConnection(url);
            // Create a Statement
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("select .... WHERE ....'");
            while (rs.next()) {
                System.out.println(rs.getString(1));
            } // end of rs while
            conn.close();
        } catch (SQLException sqle) {
            Logger.getLogger(connWithProps1.class.getName()).log(Level.SEVERE, null, sqle);
        } catch (IOException ioe) {
            Logger.getLogger(connWithProps1.class.getName()).log(Level.SEVERE, null, ioe);
}The error I get is:
SEVERE: null
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
111.111.111.111:1521:oradb","username","password"
        at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
        at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:460)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:411)
        at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:490)
        at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:202)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:474)
{code}
Although the URL prints out correctly and when I tried plugging in the URL manually, it works just fine. One other thing I noticed was the line "The file exists, or was created sucessfully" is output 3 times.
I will go back and change my code to properly close the resultset, thanks for catching that. Id rather use what I have instead of JNDI unless it's nesessary.
Edited by: shadow_coder on Jun 19, 2009 2:16 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • How to access form objects from different class?

    Hello, I am new to java and i started with netbeans 6 beta,
    when i create java form application from template i get 2 classes one ends with APP and one with VIEW,
    i put for example jTextField1 with the form designer to the form and i can manipulate it's contents easily from within it's class (let's say it is MyAppView).
    Question>
    How can i access jTextField1 value from different class that i created in the same project?
    please help. and sorry for such newbie question.
    Thanks Mike

    hmm now it says
    non static variable jTree1 can not be referenced from static context
    My code in ClasWithFormObjects is
    public static void setTreeModel (DefaultMutableTreeNode treemodel){
    jTree1.setModel(new DefaultTreeModel(treemodel));
    and in Class2 it is
    ClasWithFormObjects.setTreeModel(model);

  • Access oracle database from microsoft access?

    It is possible access to an'ORACLE database from Microsoft Access?

    Yes, that's possible.
    You can find several threads for this on the forum,e.g.
    Oracle & MS Access

  • Accessing Oracle Database from PocektPC / Palm

    Hi
    We need to develope a mobile application where client can be Palm or PocketPC device (preferably PocketPC)
    and the Server is Oracle 9 on Sun Solaris.
    Some data will be logged into PDA device and stored in the local database. Thereafter it needs to connect to Oracle and INSERT into it.
    We do not want to use any third party sw as far as possible. The client does not have App Server (so web services is not possible)
    If we have to use Palm device what are the solutions?
    If we have to use PocketPC device what are the solutions?
    thanks and regards
    Haresh Gujarathi
    eMantra Technologies.

    Haresh,
    With a max of 10 clients and 3-4 simultaneous syncs, I think your customer can run Lite in standalone mode without the App Server. Before I answer your questions, I'd like to give a brief description of the data model for Lite, which might help.
    When you enter data into your client (PPC, Palm or laptop), the data is put into an Oracle Lite Database, located on the client. When you synchronize with the Oracle Lite Mobile Server, the Lite DB on the client is synchronized with the Lite DB on the Mobile Server. This synchronization is done through http and we provide the infrastructure for this process.
    Once the data is on the Mobile Server, the data on the Oracle Lite DB can be inserted into the Oracle 9i DB through JDBC.
    When you ask about the Wi-fi connection, what exactly are you speaking of? For example, do you mean an 802.11b connection between the Lite client and the Mobile Server, and then an additional 802.11b connection between the Mobile Server and the 9i DB? In both cases, this can be done because it's simply a different mode for the transport of data.
    1. If Lite is not in the picture at all, then you can simply use one of Oracle's connectors (e.g. JDBC) to access the 9i Database.
    2. Yes, .NET is supported in Oracle Lite, releases 5.0.2.8 and higher.
    3. I'll have to do some further research for the answer to this question to see if it's possible to write an app that can connect to the Lite DB on Palm using Mobile VB.
    4. #2 can be done and it might be possible to do #3.
    5. There are some tutorials on OTN. Here is the link:
    http://otn.oracle.com/products/lite/tutorials/index.html
    Please let me know if you have additional questions.
    Cheers,
    Junius

  • Accessing Oracle Database from PcoektPC / Palm

    Hi
    We need to develope a mobile application where client can be Palm or PocketPC device (preferably PocketPC)
    and the Server is Oracle 9 on Sun Solaris.
    SOme data will be logged into PDA device and stored in the local database. Thereafter it needs to connect to Oracle and INSERT into it.
    We do not want to use any third party sw as far as possible. The client does not have App Server (so web services is not possible)
    If we have to use Palm device what are the solutions?
    If we have to use PocketPC device what are the solutions?
    thanks and regards
    Haresh Gujarathi
    eMantra Technologies.

    Haresh,
    With a max of 10 clients and 3-4 simultaneous syncs, I think your customer can run Lite in standalone mode without the App Server. Before I answer your questions, I'd like to give a brief description of the data model for Lite, which might help.
    When you enter data into your client (PPC, Palm or laptop), the data is put into an Oracle Lite Database, located on the client. When you synchronize with the Oracle Lite Mobile Server, the Lite DB on the client is synchronized with the Lite DB on the Mobile Server. This synchronization is done through http and we provide the infrastructure for this process.
    Once the data is on the Mobile Server, the data on the Oracle Lite DB can be inserted into the Oracle 9i DB through JDBC.
    When you ask about the Wi-fi connection, what exactly are you speaking of? For example, do you mean an 802.11b connection between the Lite client and the Mobile Server, and then an additional 802.11b connection between the Mobile Server and the 9i DB? In both cases, this can be done because it's simply a different mode for the transport of data.
    1. If Lite is not in the picture at all, then you can simply use one of Oracle's connectors (e.g. JDBC) to access the 9i Database.
    2. Yes, .NET is supported in Oracle Lite, releases 5.0.2.8 and higher.
    3. I'll have to do some further research for the answer to this question to see if it's possible to write an app that can connect to the Lite DB on Palm using Mobile VB.
    4. #2 can be done and it might be possible to do #3.
    5. There are some tutorials on OTN. Here is the link:
    http://otn.oracle.com/products/lite/tutorials/index.html
    Please let me know if you have additional questions.
    Cheers,
    Junius

  • Trying to access 10gr2 database from sqlplus utility but it connects to 11g

    Hi All,
    I am facing below issue while access 10gr2 database from sqlplus.
    I am having two oracle homes on one server one belongs to 11gr2 and another belongs to 10gr2.
    I want to access a 10gr2 database through sqlplus utility.but instaed of connecting to 10gr2 it is connecting to 11gr2 after I enter a user name and passowrd.
    I have set all the env variables such as oracle_home ,oracle_sid and path with respect to Oracle 10gr2.
    Can you please let me kno what I need to do to connect to 10gr2 database and not 11gr2 database through sql plus.
    Let me know if I need to give any more details on this.
    Best Regards,
    Dipti S

    Hi Rocky,
    I got the resolution.
    I made a mistake by creating an oracle instance/service(e.g. fsdmo) when Oracle_home was pointing to 11gR2 Directory.so that service was refering to 11gr2 oracle home.
    hence when I was setting oracle_sid(fsdmo) and trying to access database instance from 11g sqlplus utility ,it was directing to 11g and not 10g since oracle service was pointing to 11g.
    So now after chnaging the oracle home directory to 11g,I am creating a service and its working fine.
    thank you so much for responding.
    hope I am clear with my reply.
    Best Regards,
    Dipti S

  • How to connect to  Oracle database from webdynprojava application

    Hi
    How to connect to  Oracle database from webdynprojava application. where can we provide the code to connect to database.?
    Thank You.

    Hi,
    You need to create  Java Bean model. The bean is a typical java bean with default constructor, getter and setter. You can have additional methods for query etc. The attributes in the class will be your model node and attributes.
    However you need to configure the connection and create JNDI using visual administrator before writing the code.
    You can also consider writing Session EJB with oracle and using them in WD.
    http://help.sap.com/saphelp_nwce10/helpdata/en/45/dcaa4f05535591e10000000a1553f7/frameset.htm
    Srini

  • How to access Oracle database using UNIX?

    Hi,
    Does anyone know how to access Oracle database Oracle 8i that is hosted on unix server via unix command line?
    Thanks,
    Willy

    Well, Oracle probably has a command line tool. I think it's called sqlplus or somesuch. Check you Oracle docs.
    Of course, given that this is a Java forum, it's remotely possible that you're actually asking about accessing the database from a Java program.
    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/

  • Connect on an oracle database from another computer

    hi all,
    i installed oracle database 10g express as well as sql developer on one of my laptop. Everything is ok as of the moment.
    Now, i want to access that oracle database from my another laptop. Is this possible? let me know what should i do in order to achieve this.
    thanks.

    user13169035 wrote:
    thanks for the help. basically here is the setup.
    i have 2 laptops. the first one has oracle 10g database express install and sql developer. i can query my database from here using sql developer.
    now, on my second one, i want to access the data from the database that i created from the first laptop. i want to access the data from the database from the first laptop using sql developer which i also installed on the 2nd laptop.
    i already tried the link from http://www.oracle.com/technology/software/products/database/xe/files/install.102/b25144/toc.htm but didnt work (or maybe i missed something important).
    What from the link did you try to follow? Did you try to follow the information in the link i posted, specifically ...
    "4.4 Making Oracle Database XE Server Available to Remote Clients"
    Once you have done that. You will need to know the IP or possible computer name of the computer on the network which is hosting the database (it would be easiest if the laptop with the database had a static IP assigned by your router, assuming this is a home setup, and you use that for your connection). You will need that information to create a new connection in SQLDeveloper on the laptop without the database installed.
    Aside from that you may have to deal with windoze firewall issues and the like, but that removes this from being an Oracle question, you should be able to use google to deal with any issues you encounter in that.

  • How to connect to oracle database from visual basic 2010 express edition

    I have installed visual basic 2010 express edition on windows xp. But visual basic 2010 express edition supports Microsoft sql server database file,Microsoft sql server compact 3.5, Microsoft access database file. I want to connect to oracle database from visual basic 2010 express edition. So what drivers are required and how to do connectivity?

    Hello,
    I wasn't clear on what you were using to make the connection. I had a look in Visual Studio 2010 (don't have express to test sorry).
    I think you mean the Data Sources available under the menu Data-> Datasources. this seems to match the description you give when I
    look at the list of datasource options.
    In here you can make ODBC connections via the Microsoft .net Data Provider .
    If you select ODBC as a datasource you can see listed the DSN's you created - for example I see 2 which use the Oracle ODBC driver.
    This assumes you installed an Oracle Client + the oracle version of the ODBC driver (comes with the oracle client).
    Once you created a server connection then you should see it in the server explorer.
    You can also download the Oracle Developer Tools for Visual Studio which is an add on for VS.
    ** I suspect this is only for VS 2010 and I didn't see that Express was supported.
    http://www.oracle.com/technetwork/developer-tools/visual-studio/overview/index-097110.html
    Let me know if that helps.
    John

  • Access Oracle 9i from a Client Application without Oracle Client Install.

    Is it possible to access an Oracle Database from a Client Application without having an oracle Client Installation ?
    I want to write a program that connect to an Oracle Server. I use Borland C++. But my Programs only works with having the Client Oracle Software installed on the Client. Is there any way to realise this ?

    The way that 99% of the people that want to do this manage is to write Java code that connects to the database via JDBC, using Oracle's thin JDBC driver.
    If you absolutely have to use C++, you can purchase thin ODBC drivers from third parties (DataDirect for example) that will connect to the database without the Oracle client. I'm not aware of any thin, free ODBC drivers.
    Justin

  • Access Oracle database on ARM platform

    Hi
    I am trying to access Oracle database on ARM platform.
    Is anyone has experience about that?
    It seems that the instance client has no ARM version.
    Thanks for any suggestion.

    Pro*C and oci are cool but I recomend the Oracle Template Library.
    It is much simpler and easier to use.
    It is just one .h file which includes a set of classes which are a thin wraper over oci.
    Try it, you don't know what you are missing.
    (That goes for the oci and pro*c advocates too :)
    http://www.geocities.com/skuchin/otl/home.htm
    null

  • Oracle Database 10g Release 2 - Free Desktop Data Center DVDs

    Hi,
    I have registered for the subject Oracle Database 10g Release 2 - Free Desktop Data Center DVDs more than a month ago, but I am still awaiting to receive them.
    Raghavan Karoth (Mahamaya Websoft)
    775 Dupont Street
    Toronto, On, M6G1Z5
    Tele:1-514-667-0577

    "10203_vista_w2k8_x86_production_db.zip" had been created and this folder size shows 63 MB Your download is not complete, zipfile is almost 800MB, from the download site:
    10203_vista_w2k8_x86_production_db.zip (797,326,161 bytes)
    You are right, home editions are not supported. That does not necessarily mean, it does not work, but it's your risk.
    Werner

  • XGEN accessing Oracle Database

    I'm an Oracle Account Manager and I have a customer with a XGEN application accessing Informix Database. They want to keep this application and move from Informix to Oracle, and this application must access Oracle. Does any one have an experience like this?

    Hi Bharathwaj,
      Thanks for the reply. it has really helped me a lot.
    i wanted to ask one more thing...
    In our webdynpro application (deployed on WAS) we are  required to fetch and update data in oracle database. The restriction here is we are required to use DSN (provided by Primavera Inc..for connection). We are using connection pool, where we have configured data source with DSN(system DSN) with appropriate parameters.
    We have tested the dSN for extensive data transfer from our local jvm's...but when used with J2EE on WAS..its not that stable, when used to transfer data say for more than 2-3 times, gives SQL Exception with general error. Then after, when J2EE engine is stopped...it starts working fine...then again after when J2EE started, same problem occurs...
    Is it some problem with memory??
    Because our server has 1 GB RAM + 4 GB VM there fore total 5GB available memory. Previous performance of server was very slow due to wrong VM setting...
    Now also the performance is not that good...jalunch.exe consumes upto 1.4 gB of memory..is it ok..or something wrong???
    Is there alternative best way to talk to external oracle database from WAS J2EE...or connection pool is the best possible method..
    If there are any settings to be done on server also..
    fine..we have complete access of it...
    Please help..

  • Accessing the ServletContext from a class that is not a Servlet?

    Is there any way of accessing the ServletContext from a class that is not a
              Servlet? The class is being used as part of a Web Application.
              Thanks.
              

    http://www.mozilla.org/mirrors.html
    Mozilla has download mirrors around the globe. If it is on the list, it is trustworthy.

Maybe you are looking for