This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes TNSAddress.SOException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "TNSAddress.SOException" Watch "TNSAddress.SOException" New topic
Author

TNSAddress.SOException

Sri Addanki
Ranch Hand

Joined: Apr 27, 2001
Posts: 195
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
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Apr 27, 2001
Posts: 195
Hi Jamie Robertson:
Thanks for the timely help and suggestion. It works.
Thanks,
Sri
 
wood burning stoves
 
subject: TNSAddress.SOException