• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

TNSAddress.SOException

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am getting this exception when i am trying to
run a simple java program from command line.
oracle.net.TNSAddress.SOException.
at oracle.net.TNSAddress.ServiceAlias.initFromNVPair(Unknown Source)
at oracle.net.TNSAddress.ServiceAlias.initFromString(Unknown Source)
at oracle.net.resolver.AddrResolution.resolveAddrTree(Unknown Source)
at oracle.net.resolver.AddrResolution.resolveAndExecute(Unknown Source)
at oracle.net.ns.NSProtocol.establishConnection(Unknown Source)
at oracle.net.ns.NSProtocol.connect(Unknown Source)
at oracle.jdbc.ttc7.TTC7Protocol.connect(TTC7Protocol.java:1213)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:209)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:249)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at TestJdbc.putData(TestJdbc.java:37)
at TestJdbc.main(TestJdbc.java:21)

The database i am using Oracle8i Enterprise Edition.
Here is my source code.
import java.sql.*;
public class TestJdbc
{
public static void main (String[] args)
{
TestJdbc t1 = new TestJdbc();
if (args.length <= 0)
{
return;
}
int id = new Integer(args[0]).intValue();
String fname = args[1];
String lname = args[2];
System.out.println("rows inserted = " +
t1.putData(id, fname,lname));
}
public int putData(int id,
String fname,
String lname)
{
String url= "jdbc racle:thin:@naga";
String driver =
"oracle.jdbc.driver.OracleDriver";
int rowsInserted = 0;
Connection con = null;
try
{
Class.forName(driver);
con = DriverManager.getConnection
(url,"SYSTEM","MANAGER");
String sql = "INSERT INTO Emp
(id,fname,lname)
VALUES(?,?,?)";
PreparedStatement pstmt =
con.prepareStatement(sql);
pstmt.setInt(1,id);
pstmt.setString(2,fname);
pstmt.setString(3,lname);
rowsInserted = pstmt.executeUpdate();
}
catch (ClassNotFoundException e)
{
System.out.println("The Exception
is . " + e.getMessage());
}
catch (SQLException e)
{
System.out.println("The SQL
Exception is . " + e.toString());
}
catch (Exception e)
{
System.out.println("The Exception
is . " + e.toString());
}
return rowsInserted;
}
}
Any suggestions I am rattling with this issue for the last couple of hours.
Thanks,
Addanki
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which line of code is throwing the exception?
If it is the connection, then it may be your Connection URL:
you are missing the Oracle instance name and the port that instance is listening( make sure Oracle is listening at this port too! ).
Proper URL Format:

your code only specifies the server.
Jamie
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jamie Robertson:
Thanks for the timely help and suggestion. It works.
Thanks,
Sri
 
I want my playground back. Here, I'll give you this tiny ad for it:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic