5
public static  Connection getConnection()throws SQLException,ClassNotFoundException
       { String username="scott";
            String password="tiger";

            String url="jdbc:oracle:thin:@localhost:1521";
        Connection connection = null;
        System.out.println("before class");
                   Class.forName("oracle.jdbc.OracleDriver");
                   System.out.println("Before connection");
                connection=DriverManager.getConnection(url,username,password);
           System.out.println("CONNECTED");
        return connection;
       }

Connection Name: orcl UserName:scott Password:tiger connection details:scott@

I am using Oracle g11 Release 2 and I already included the ojdbc.jar in my build path. When trying to establish the connection, I get the following stack trace error:

java.sql.SQLException: Io exception: Invalid connection string format, a valid format is: "host:port:sid" at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333) at oracle.jdbc.driver.OracleConnection.(OracleConnection.java:404) at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.adobe.util.DBConnection$DBUtil.getConnection(DBConnection.java:23) at com.adobe.daoimpl.DBimplementation.registration(DBimplementation.java:21) at com.adobe.service.AdobeService.registration(AdobeService.java:13) at webservice.Web.service(Web.java:16) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397) at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186) at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454) at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281) at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

Thanks in advance

kmatyaszek
  • 19,016
  • 9
  • 60
  • 65
Kali
  • 73
  • 1
  • 2
  • 10

6 Answers6

9

Just solved this issue by using: jdbc:oracle:thin:@//ipadress:portnumber/service_name

janisz
  • 6,292
  • 4
  • 37
  • 70
4

You are missing SID (or service name) on the end of connection string.

It has to be "host:port:sid"

jakub.petr
  • 2,951
  • 2
  • 23
  • 34
  • Added sid and then it was showing the below error This is what i gave.orcl is my connection name please correct if I am doing wrong "jdbc:oracle:thin:@localhost:1521:orcl" It was showing me the below error after adding SID as orcl java.sql.SQLException: ORA-28000: the account is locked at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289) at oracle.jdbc.ttc7.O3log.receive2nd(O3log.java:496) at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:278) could you please help me in this – Kali Dec 02 '12 at 10:56
2

it should be

String url=" jdbc:oracle:thin:@Localhost:1521:XE";

smita
  • 43
  • 1
  • 8
1

Add the database SID in your connection string.

String url="jdbc:oracle:thin:@localhost:1521:SID_GOES_HERE";
Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
  • It was showing me the below error after adding SID as orcl This is what i gave.orcl is my connection name please correct if I am doing wrong "jdbc:oracle:thin:@localhost:1521:orcl" java.sql.SQLException: ORA-28000: the account is locked at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289) at oracle.jdbc.ttc7.O3log.receive2nd(O3log.java:496) at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:278) could you please help me in this – Kali Dec 02 '12 at 10:53
  • ALTER USER username ACCOUNT UNLOCK, Also make sure that your user has been granted the correct permissions. – Kevin Bowersox Dec 02 '12 at 10:55
  • No luck I doesnt know about oracle connections and all.Could please help me in this.I am creating local connection in sql developer and in the connection I am changing to Local/Bequeath and creating a database and in this I am creating tables.Is there anything that has to be done rather than this – Kali Dec 02 '12 at 11:02
  • Connect as the sys user in sql developer. You will see "Other Users" expand this. Right click the schema and view properties. Within this dialog should be an option to unlock the user and grant privileges. I do not have sql developer handy so these instructions are not exact. – Kevin Bowersox Dec 02 '12 at 11:10
  • I am able to connect but it says table/view is not there but I created a table with name adobetrail and checkd in sqlplus SQL> select * from tab; TNAME TABTYPE CLUSTERID ------------------------------ ------- ---------- ADOBETRAIL TABLE Below was my console message CONNECTED java.sql.SQLException: ORA-00942: table or view does not exist at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289) – Kali Dec 02 '12 at 11:22
1

And your SID probably is XE, so it should be jdbc:oracle:thin:Localhost:1521:XE

sorencito
  • 2,517
  • 20
  • 21
0

I had the same problem, same error:

java.sql.SQLException: Io exception: Invalid connection string format, a valid format is: "host:port:sid"

I resolved it by updating my JDBC driver. In my particular case, from ojdbc7.jar to to ojdbc8-12.2.0.1.jar

Pierre
  • 2,335
  • 22
  • 40