0

I have an account, password and the URL.

3
  • 2
    What is a web based database? Commented Nov 24, 2009 at 22:37
  • Sorry its just a server based database, you access it through a web browser. im just unfamiliar with database programing. Commented Nov 24, 2009 at 23:15
  • @Mo: Oracle JDBC downloads: oracle.com/technology/software/tech/java/sqlj_jdbc/index.html Commented Nov 24, 2009 at 23:25

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

4 Comments

+1 for detail. Plus it's funny to read OMG Ponies throughout the answer.
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.
The Oracle driver that best matches the JDK you're using, of course.
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 oracle.com/technology/software/tech/java/sqlj_jdbc/index.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.