I'm struggling with establishing connection to my database using JDBC. I've done already all necessary things mentioned in documentation.
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?
You are missing a colon - use
jdbc:oracle:thin:@localhost:1521:xe
^
instead of
jdbc:oracle:thin@localhost:1521:xe
^^^
as the connection string.
See also https://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html
... Where the URL is of the form:
jdbc:oracle:<drivertype>:@<database>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.