Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBC connection problems

Status
Not open for further replies.

Toe

Programmer
Oct 26, 2001
71
0
0
GB
hi,

i am tying to establish a connection to an oracle database with the following code:

Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println ("Registered Oracle Driver");
con1 = DriverManager.getConnection ("jdbc:eek:racle:thin:mad://"+connectionString,userName,password);
System.out.println ("Made connection");

(where connectionString, userName and password are variables containing appropriate values and connectionString is of the form <servername>:<port>/<dbname> )

i *am* gettign the message "Registered Oracle Driver" but not the message "Made connection" and I am getting the error : "java.lang.NoSuchMethodError"
 
I'm not an Oracle expert, but this could indicate a mismatch between your Oracle driver- and Java version or a mismatch between ojdbc5.jar (or ojdbc14.jar) and orai18n.jar
 
Here is the code I use to connect through JDBC:

Code:
try {
		// Load the JDBC driver
		Class.forName("oracle.jdbc.driver.OracleDriver");

		// Create a connection to the database
		String serverName = "127.0.0.1";
		String portNumber = "1521";
		String sid        = "SOMESID";
		String url        = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
		String username   = "UNAME";
		String password   = "pword";
		connection = DriverManager.getConnection(url, username, password);
	} catch (ClassNotFoundException e) {
		// Could not find the database driver
		message = "Could not find the database driver";
	} catch (SQLException e) {
		// Could not connect to the database
		message = "Could not connect to the database";
	}
 
Let me also ask, what is the web server you are using? Tomcat? JBoss?
 
hi , thanks for the responses everybody.

Information i should have put in the first mesage......

1) This is actually code called form a 'bean area' on an oracle form. Although that might sound like it complicates it, it really acts like an applet.

2) This worked fine in the development environment (ie. database and application server), fine on the 'user test' environment - but then produced thsi area in the production environment.

hence, i beleive it to be something to do with the config of the appserver - for example my first guess was the 'jar' files it downloads. but i have now alligned these between the systems.
 
Definitely it's a classpath problem: your drivers are different in those environments.

Cheers,
Dian
 
connection = DriverManager.getConnection(url, username, password);

Compare the versions of the jdbc drivers.
The app is finding the drivers, but it doesn't recognise the method.
I had the very same problem with my jdbc drivers for SQL Server, and i had to change the sintax for the connection string. In my case the user and password also became part of the so called "url", and the DriverManager.getConnection(url,user,password) changed into DriverManager.getConnection(url);

I can't give you the exact sintax, because it seems to me that the url sintax for oracle is a bit different than the one for SQL Server. Anyway, my url connection string is now at this form:

String DbName="something";
String UName="username";
String password="password";
String serverName="server";
String portnumber="port";
String url = "jdbc:sqlserver://"+serverName+":"+portNumber+";DatabaseName="+DbName+";user="+Uname+";password="+Upassword+";";

Do remember that this is the sintax for a SQL Server connection.

Good Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top