This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSP and the fly likes jstl:sql  no suitable driver error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl:sql  no suitable driver error" Watch "jstl:sql  no suitable driver error" New topic
Author

jstl:sql no suitable driver error

k matt
Greenhorn

Joined: Oct 12, 2005
Posts: 22
Hi,
OS WIN 2K, Tomcat is 4.1.3 , jdk 1.4.2_03 , udb is 7.2
When I use the following code in a jsp it works without a problem

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
con = DriverManager.getConnection( ); // proper arguments inside

But, If I replace the above with the following in the same file , I get
the exception

javax.servlet.ServletException: Unable to get connection, DataSource
invalid: "No suitable driver"

<sql:setDataSource var="myDataSource" driver="COM.ibm.db2.jdbc.app.DB2Driver" url="jdbc :db2:mydb" user="abc" password="xyz" />
<sql:query var="rowdetails" dataSource=${myDataSource}>
SELECT a, b, c from sometable
</sql:query>



I have looked into the other similar postings in the same group. But no success. I have not configured a default data source in server.xml and I dont have entries in /WEB-INF/web.xml for this data source

Thanks,
K matt

[ October 19, 2005: Message edited by: k matt ]

[ October 19, 2005: Message edited by: k matt ]

[ October 19, 2005: Message edited by: k matt ]
[ October 19, 2005: Message edited by: k matt ]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
The "No suitable driver" means that it can't find a driver for the URL string you provided.
Double check you have the same url both in the getConnection() call, and in the url of the setDataSource tag. (those "proper arguments" you mentioned.)
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
Is the space in between "jdbc" and "db2" in the url a typo?
[ October 19, 2005: Message edited by: Eddy Lee Sin Ti ]

SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
k matt
Greenhorn

Joined: Oct 12, 2005
Posts: 22
That space happened when I cut and pasted to the web. The code which is working as a regular jsp is like this


Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
con = DriverManager.getConnection("jdbcb2:mydb","uid","somepassword");

and the using jstl is like this

<sql:setDataSource var="example"
driver="COM.ibm.db2.jdbc.app.DB2Driver"
url="jdbcb2:mydb"
user="uid"
password="somepassword" />
<sql:query dataSource="${example}" var="results" >..... </sql:query>


Thanks for looking into this

k Matt

[ October 20, 2005: Message edited by: k matt ]

[ October 20, 2005: Message edited by: k matt ]

[ October 20, 2005: Message edited by: k matt ]
[ October 20, 2005: Message edited by: k matt ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61458
    
  67

OK, here I come with the wet blanket...

You are spending an enormous amount of time trying to figure out how to do something in a manner that is generally considered extremely poor practice; namely, performing SQL on the pages. Even the framers of the JSTL sql tags recommend that the tags be used only in quick prototypes and not in production code.

I feel that you could be spending your time better by using it to refactor your application into a better structure that follows accepted best practices.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
k matt
Greenhorn

Joined: Oct 12, 2005
Posts: 22
I am trying to do a prototype .

Kurian
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61458
    
  67

That's ok, but do you not think that you are spending way too much time on it? Even in a prototype, I'd spend my time on more useful pursuits. That's just my opinon; it's your decision of course.
k matt
Greenhorn

Joined: Oct 12, 2005
Posts: 22
Thank you for your concern.

k matt
SP Nam
Ranch Hand

Joined: Oct 15, 2003
Posts: 41
Hi Matt

You need to have .jar file in your WEB-INF lib.

For example, Oracle db needs classes12.jar in WEB-INF/lib folder.
For DB2 it should be different.

Thanks
SP Nam
k matt
Greenhorn

Joined: Oct 12, 2005
Posts: 22
Hi,
I am not getting a ClassNotFoundException. I think the problem I am having is the syntax.

Matt
k matt
Greenhorn

Joined: Oct 12, 2005
Posts: 22
At last the problem is fixed. I took out the var attribute inside sql:setDataSource tag and it works.

Matt
Chirags Jain
Greenhorn

Joined: Jun 28, 2011
Posts: 1
BUt how is the problem solved by pushing out var. Plese show the corrected code
dinesh kumary
Greenhorn

Joined: Oct 02, 2013
Posts: 1
keep var at the end i.e after user name and passwords it worked for me :jumpingjoy:
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jstl:sql no suitable driver error