wood burning stoves 2.0*
The moose likes JDBC and the fly likes SQLException while registrering driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQLException while registrering driver" Watch "SQLException while registrering driver" New topic
Author

SQLException while registrering driver

Jeff Dube
Ranch Hand

Joined: Jun 14, 2001
Posts: 44
Hi,
I made a JSP and i need to connect to an oracle database. I am using Tomcat and i know that i need to include the JDBC driver in the lib directory. I have taken the classes12.zip to oracle/jdbc/lib directory and unziped it in the tomcat lib directory. Here is the Error:
SQLException: No suitable driver
Can somebody help me resolve this problem???
Thank you..
Jeff
Jeff Dube
Ranch Hand

Joined: Jun 14, 2001
Posts: 44
I am sorry, Hewre is a part of my code:

public String connect() {
try {
//DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
return "Driver Loaded!";
} catch (Exception E) {
return "Unable to load driver.";
}
}

public String insertSomething() {
try {
Connection Conn = DriverManager.getConnection("jdbc racle:thin:scott/tiger@server:1521:server");
Statement Stmt = Conn.createStatement();

String insert = "INSERT into jsp_jeff VALUES('congratulation');";

int stmtInt = Stmt.executeUpdate(insert);

Stmt.close();
Conn.close();
return "Inserted row " + stmtInt;
} catch (SQLException E) {
return "SQLException: " + E.getMessage();
} catch (Exception E) {
return "Error " + E.toString();
}
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

When do you get the Exception?
When you call insertSomething()?
Have you called connect() first?
(Did you notice you are instantiating the connection object in insertSomething()?)
If you have already called connect() and then call insertSomething() and are getting this message back, then I'm not positive, but it sounds like you might be loading the wrong driver for your data source.

!_I_Know_Kung_Fu_!
Jeff Dube
Ranch Hand

Joined: Jun 14, 2001
Posts: 44
This is my jsp file
<html>
<head>
<title>Insert something into a database</title>
</head>
<body>


<h1>Here is the JSP</h1>

<jsp:useBean id="insert" class="JspInsert.DataBaseInsert" scope="request">
<jsp:setProperty name="insert" property="something" value="something already in the bean" />
</jsp:useBean>
<% out.print(insert.connect()); %>


<% insert.setSomething("a new something to insert"); %>


<% out.print(insert.insertSomething()); %>
</body>
</html>
Jeff Dube
Ranch Hand

Joined: Jun 14, 2001
Posts: 44
Sorry,
Here is the jsp file



<h1>Here is the jsp</h1>

<jsp:useBean id="insert" class="JspInsert.DataBaseInsert" scope="request">
<jsp:setProperty name="insert" property="something" value="something already in the bean" />
</jsp:useBean>
<% out.print(insert.connect()); %>


<% insert.setSomething("a new something to insert"); %>


<% out.print(insert.insertSomething()); %>
john_guthrie
Greenhorn

Joined: Jun 14, 2001
Posts: 16
The way the DriverManager works, from what I remember, is you register x number of drivers with it. In your case x=1, and the driver is oracle.jdbc.driver.OracleDriver. If the class.forName were failing, i.e. the OracleDriver wasn't being found in your classpath, you'd get a different exception. So I assume the oracle driver got loaded into the DriverManager.
The next step is at Connection creation time. You provide a URL for your connection, and basically the DriverManager runs through all the drivers that have registered with it and asks each one in turn if it can handle this URL. The first one that can responds with a usable Connection. If none of them like the URL, it falls through and you get a "No suitable driver" message.
So the short answer is that there is something wrong with your URL. I don't know all the ways you can form an Oracle URL, and your post has some smiley in the middle of it, so I can't say what the exact problem is in the URL, but it's the URL. Read the Oracle docs if you cannot tweak it yourself.
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

I think he is right, you need to tweak something in these lines:

Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Hi,
Syntax should be something like this,


protocol:sub-protocol:driver-type:user-name: pwd


jdbc: oracle:driver-type:user/password@database


For a detailed explanation, follow the link,

Goto Oracle .

HTH..
Anil

SCJP 1.5, SCEA, ICED (287,484,486)
Jeff Dube
Ranch Hand

Joined: Jun 14, 2001
Posts: 44
Thank you guys,
you were right!!! Thanks
By inserting the classes12.zip to my classpath, i solved my problem. Thank you for helping me.
Jeff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQLException while registrering driver