File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Invalid oracle URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Invalid oracle URL" Watch "Invalid oracle URL" New topic
Author

Invalid oracle URL

Ramesh kangamuthu
Ranch Hand

Joined: Mar 13, 2007
Posts: 79
Hi,
When I try to establish the connection to the oracle 9i database server
from my main method java client,I got "Invalid Oracle URL specified" exception.I have given the code below.I hope that the problem will be solved very soon.I use "classes12.jar" as JDBC Driver for my program.please help me to solve the problem.because I am in a hurry to complete the project,which has the remaining work as oracle JDBC connection.

//Example program for oracle database connection

import java.sql.*;
import oracle.jdbc.OracleDriver;

public class CRMOracleAccess
{
public static void main(String[] args) throws ClassNotFoundException
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con1=DriverManager.getConnection("jdbcracleci8@CRM2","scott","tiger");
System.out.println("Connection has been established");
Statement stmt=con1.createStatement();
stmt.executeUpdate("insert into Marketing values('team1123','Vimal')");
System.out.println("A record has been inserted");
ResultSet rs=stmt.executeQuery("select * from Marketing where customer_id="+"'team123'");
while(rs.next())
{
System.out.println("Customer ID is "+rs.getString("customer_id")+"Customer name is "+rs.getString("customer_name"));
}
}
catch(SQLException ex)
{
System.err.println("SQLException is"+ex.getMessage());
System.err.println("Error Code is "+ex.getSQLState());
//ex.printStackTrace();
}
}
}
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

Does this work from your operazting system command prompt?

> tnsping CRM2
or
> tnsping80 CRM2

Also Oracle advises to register your driver first:


Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Ramesh kangamuthu
Ranch Hand

Joined: Mar 13, 2007
Posts: 79
Hi Jan,
I have given the wrong database name as CRM2 and now I corrected it as "Srm".
the command "tnsping Srm" works and displays

attempting to contact <DESCRIPTION = <ADDRESS_LIST = <ADDRESS = <PROTOCOL = TCP><HOST =sys9><PORT =1521>>><CONNECT_DATA =<SERVER = DEDICATED><SERVICE_NAME = Srm>>>
ok <20 msec>

But from my java application there is no connection established and also no error.

also i changed my code into as follows
Connection con1=DriverManager.getConnection("jdbcracle:thin@sys9:1521:Srm","scott","tiger");

but still it is resultless.

thanks ans regards,
Ramesh kangamuthu
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

What are the errors when using the thin driver?
You told that there are no errors showing with the oci driver, but nothing about your thin driver attempt.
Showing us the complete error trace will help us to help you.


Also, your insert statement is
insert into Marketing values('team1123','Vimal')
You did not specify column names.
How sure are you that the value 'team1123' is inserted into column customer_id, and not in some other column?

And, in your select, you use this query

select * from Marketing where customer_id='team123'
'team123' is different from the value 'team1123' you inserted. This might explain why the select does not return a row.

Regards, Jan
[ March 18, 2007: Message edited by: Jan Cumps ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid oracle URL