Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1044807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:53:12+00:00 2026-05-16T15:53:12+00:00

This is my first Java application I am creating (using Eclipse IDE) and the

  • 0

This is my first Java application I am creating (using Eclipse IDE) and the second Oracle based app (I’m a .NET/MSSQL guy for years). The first Oracle app I wrote in .NET did not have any issues, and I’m trying to connect to the same server.

  • I have installed:
    • ‘Java 2 Platform, Enterprise Edition 1.4 SDK’
    • ‘Java DB `10.5.3.0’
      -‘Java(TM) 6 Update 21
    • ‘Java(TM) SE Development Kit 6 update 21
    • ‘Oracle IRM Client’ (11g)
    • Oracle 11g Release 2 JDBC Drivers (ojdbc6.jar)

My code is very simple. Here it is:

  OracleDataSource ods = new OracleDataSource();
            ods.setURL("jdbc:oracle:oci:@");
            ods.setUser("username");
            ods.setPassword("password");
            ods.setServerName("servername");
            ods.setPortNumber(1549);
            ods.setServiceName("foo.myservice.com");
   Connection conn = ods.getConnection();

I get below exception:

Exception in thread “main” java.sql.SQLException: ORA-12560: TNS:protocol adapter error

at oracle.jdbc.driver.T2CConnection.checkError(T2CConnection.java:737)
at oracle.jdbc.driver.T2CConnection.logon(T2CConnection.java:401)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T2CConnection.<init>(T2CConnection.java:148)
at oracle.jdbc.driver.T2CDriverExtension.getConnection(T2CDriverExtension.java:53)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:157)
at Select.GetScalar(Select.java:47)
at Job.Run(Job.java:20)
at Main.main(Main.java:19)

I have google’d the hack out of this.. I’ve tried adding a ‘TNS entry to the tnsnames.ora file’. I’ve tried adding ‘##NAMES.DIRECTORY_PATH = (TNSNAMES, EZCONNECT)’ to the sqlnet.ora file. I’ve tried various other things but nothing is working.

Has anyone experienced this before and has any clue on how to get this to work?? Am I using the wrong version? Server is remote (I don’t have Oracle server installed locally, just client). Maybe I have wrong version of Java SDK or the wrong version of the JDBC .jar file?? I just need to connect to Oracle and run a single simple query! Thanks much for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:53:13+00:00Added an answer on May 16, 2026 at 3:53 pm

    Try using the type IV JDBC driver instead of OCI if you can. The thin url looks like this:

    jdbc:oracle:thin:@host[:port]/service
    

    I’d try code that looked more like this (fill in your defaults for the driver, URL, username, and password):

        package persistence;
    
        import java.sql.*;
        import java.util.ArrayList;
        import java.util.HashMap;
        import java.util.List;
        import java.util.Map;
    
        public class DatabaseUtils
        {
    
            private static final String DEFAULT_DRIVER = "";
            private static final String DEFAULT_URL = "";
            private static final String DEFAULT_USERNAME = "";
            private static final String DEFAULT_PASSWORD = "";
    
            public static void main(String[] args)
            {
                String driver = ((args.length > 0) ? args[0] : DEFAULT_DRIVER);
                String url = ((args.length > 1) ? args[1] : DEFAULT_URL);
                String username = ((args.length > 2) ? args[2] : DEFAULT_USERNAME);
                String password = ((args.length > 3) ? args[3] : DEFAULT_PASSWORD);
    
                Connection connection = null;
    
                try
                {
                    connection = createConnection(driver, url, username, password);
                    DatabaseMetaData meta = connection.getMetaData();
                    System.out.println(meta.getDatabaseProductName());
                    System.out.println(meta.getDatabaseProductVersion());
                }
                catch (Exception e)
                {
                    e.printStackTrace(); 
                }
                finally
                {
                    close(connection);
                }
            }
    
            public static Connection createConnection(String driver, String url, String username, String password) throws ClassNotFoundException, SQLException
            {
                Class.forName(driver);
    
                if ((username == null) || (password == null) || (username.trim().length() == 0) || (password.trim().length() == 0))
                {
                    return DriverManager.getConnection(url);
                }
                else
                {
                    return DriverManager.getConnection(url, username, password);
                }
            }
    
            public static void close(Connection connection)
            {
                try
                {
                    if (connection != null)
                    {
                        connection.close();
                    }
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
            }
    
    
            public static void close(Statement st)
            {
                try
                {
                    if (st != null)
                    {
                        st.close();
                    }
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
            }
    
            public static void close(ResultSet rs)
            {
                try
                {
                    if (rs != null)
                    {
                        rs.close();
                    }
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
            }
    
            public static void rollback(Connection connection)
            {
                try
                {
                    if (connection != null)
                    {
                        connection.rollback();
                    }
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
            }
    
            public static List<Map<String, Object>> map(ResultSet rs) throws SQLException
            {
                List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
    
                try
                {
                    if (rs != null)
                    {
                        ResultSetMetaData meta = rs.getMetaData();
                        int numColumns = meta.getColumnCount();
                        while (rs.next())
                        {
                            Map<String, Object> row = new HashMap<String, Object>();
                            for (int i = 1; i <= numColumns; ++i)
                            {
                                String name = meta.getColumnName(i);
                                Object value = rs.getObject(i);
                                row.put(name, value);
                            }
                            results.add(row);
                        }
                    }
                }
                finally
                {
                    close(rs);
                }
    
                return results;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Application configuration: Web application using java first method of creating JAX-WS 2.0 Web Services
I have this issue: first, I execute a SQL query using Java and then
I am creating a Java application in which I need to read the first
I am following this tutorial to build my first Java 3D application. I included
I'm doing my first Java EE web application using glassfish and netbeans. When I
I'm creating my first JPA application using NetBeans. I'm unable to make the persistence
This is my first time working with file i/o in java, and it's not
I'm new to Java and this is my first post on here so hopefully
Hi i am very new to java and this is my first piece of
This is a very basic question on Java. I've read somewhere that at first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.