views:

98

answers:

2

I have an account, password and the URL.

+6  A: 

Use:

Connection connection = null;

try {
   // Load the JDBC driver
   String driverName = "oracle.jdbc.driver.OracleDriver";
   Class.forName(driverName);

   // Create a connection to the database
   String serverName = "127.0.0.1";
   String portNumber = "1521";
   String sid = "mydatabase";
   String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
   String username = "username";
   String password = "password";
   connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
   // Could not find the database driver
} catch (SQLException e) {
   // Could not connect to the database
}

Reference: Connecting to an Oracle Database

OMG Ponies
i will try that, thank you
Mo
+1  A: 

Just an addendum to OMG Ponies' answer, you will need a couple of items to proceed: 1. A JDBC driver for Oracle on your build path (Oracle offers these drivers for download) 2. The driverName variable in OMG Ponies' code has to be changed to the name of the specific Oracle driver you're using 3. The serverName variable in OMG Ponies' code should NOT be left at 127.0.0.1 but should instead be changed to the server address you mentioned. I only note this because the way you phrased your question implies an unfamiliarity with computer concepts in general and using databases with Java in particular.

spork
+1 for detail. Plus it's funny to read OMG Ponies throughout the answer.
OMG Ponies
yeah first ever time using databases with Java, and im not the strongest programmer in the world to be honest.what do you mean by a driver? and any idea which one i would need? thanks for your help and time.
Mo
The Oracle driver that best matches the JDK you're using, of course.
duffymo
My limited experience with Oracle taught me that you need to get the Oracle JDBC driver specifically meant for the Oracle version of the database you're connecting to. For example, if you're connecting to an Oracle 10g DB you need the Oracle 10g JDBC driver. You can see a list of drivers to download at http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html.
spork
Oh My God!!! Ponies.
BalusC
@Balus: Squeeeee!
OMG Ponies