File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp connection to access db

 
monica acerra
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first try at connecting db... I have set up my odbc connection in the data source admin,and I have given my data source a name.
I think my problem is in my jsp
<%
Class.forName("sun.jdbc.odbc.Driver");
java.sql.Connection connection = java.sql.DriverManager.getConnection(
"jdbc dbc:c:/tomcat/webapps/examples/jsp/monicaAcerra/ma");
java.sql.Statement statement = connection.createStatement();
java.sql.ResultSet columns = statement.executeQuery(
"SELECT * FROM url");
while(columns.next()) {
String name = columns.getString("name");
String url = columns.getString("url");
%>
<tr>
<td><%= name %></td>
<td><%= url %></td>
</tr>
<% } %>
TIA
Monica
 
vaibhav punekar
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.sql.Connection connection = java.sql.DriverManager.getConnection(
"jdbc dbc:c:/tomcat/webapps/examples/jsp/monicaAcerra/ma)
What is this c:/tomcat/webapps/examples/jsp/......?
I think you need to provide DSN name after odbc:......
Is it your DSn name or the path?
I m sorry I did not get it?
 
monica acerra
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed type-o and I guess my dns should just look like:
java.sql.Connection connection = java.sql.DriverManager.getConnection(
"jdbc dbc:ma");
,,,,
my errors are:
ERROR 505
javax.servlet.ServletException: Unable to load class sun.jdbc.odbc.Driver
,,
java.lang.ClassNotFoundException: Unable to load class sun.jdbc.odbc.Driver
TIA,
Monica
 
k b
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may have to put the zip file for the driver
sun.jdbc.odbc.Driver
into the lib directory.
Try this.
 
maha anna
Ranch Hand
Posts: 1467
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Monica,
I think the Driver name is, "sun.jdbc.odbc.JdbcOdbcDriver". Please change it and see.
regds
maha anna
 
monica acerra
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes sun.jdbc.odbc.JdbcOdbcDriver was correct!! YES!!!
I was thinking that maybe I should have imported classes like sql. or util. Why not??
Monica
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic