I'm struggling with establishing connection to my database using JDBC. I've done already all necessary things mentioned in documentation.
- I've got database working on my laptop - Oracle XE 11g rel. 2 with SID="xe", checked with SQL Developer
- I have proper driver - ojdbc6.jar - and added it to my project in Eclipse's Java Build Path properties
I wrote few basic lines with try/catch block to establish connection:
Connection myConn = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:xe", "system", "somepass"); Statement myStat = myConn.createStatement(); ResultSet myRe = myStat.executeQuery("SELECT * from PATIENTS"); while(myRe.next()){ System.out.println(myRe.getString("LAST_NAME")); } myConn.close(); myRe.close();
But after running my code i receive error "Invalid Oracle URL specified". Everything looks fine but I am just starting with JDBC.. Did I miss something?