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
2009-11-24 22:40:52
i will try that, thank you
Mo
2009-11-24 23:16:24
+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
2009-11-24 23:01:07
+1 for detail. Plus it's funny to read OMG Ponies throughout the answer.
OMG Ponies
2009-11-24 23:09:53
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
2009-11-24 23:18:23
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
2009-11-25 14:09:45