1
import java.sql.*;

public class one {

    public static void main(String[] args)

    {
            Connection conn=null;
        Statement stmt=null;

        try
        {
        Class.forName("oracle.jdbc.driver.OracleDriver");
            conn=DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/ecom","system","manager");
        stmt=conn.createStatement();
        String str="insert into country values(3,'bangladesh');";
        int k=stmt.executeUpdate(str);
        System.out.println(k);
            }
        catch(Exception e)
        {
            e.printStackTrace();

        }

    }
    }

The only jar file I added to the class path is ojdbc6.jar is there any other jar required for connecting with oracle 11g(11.2.0.1.0) I am using eclipse as IDE

here are the errors

java.sql.SQLException: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at one.main(one.java:17)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:359)
    at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422)
    at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:237)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
    ... 7 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocket`Impl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:141)
2
  • 1
    It seems you don't have any oracle database running on your machine and listening on port 1521. Commented Mar 17, 2013 at 14:31
  • 1
    And don't use ; in your query..it is not needed. Commented Mar 17, 2013 at 14:32

2 Answers 2

2

1) Please be sure database host name, port number, or database instance name are correct. 2) Be sure the TNSListener has been started ( run lsnrctl start)

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

10 Comments

Starting tnslsnr: please wait... TNS-12560: TNS:protocol adapter error TNS-00530: Protocol adapter error
in your SQLNET.ORA file, please ensure that: SQLNET.AUTHENTICATION_SERVICES= (NONE)
where is this SQLNET.ORA file and what is the default port number for 11g and how to change this port number?
Under your oracle installation, just look for a path like this: network\admin\sqlnet.ora to find the file. The default port is as you wrote 1521.
#sqlnet.authentication_services # # Syntax: A single value or a list from {beq, none, all, kerberos5, # cybersafe, radius} # Default: NONE
|
0

The connection string is malformed. It should be "jdbc:oracle:thin://@localhost:1521/ecom" Notice the transposition of // and @.

Comments

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.