• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassNotFoundException error

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I am trying to access my database using jsp. I've tried to use jsp and servlet but I am having some bizzare errors(I am not going to go into details,those problems are in the serlvets forum). So I've decided to connect to my database directly from the jsp.

Here is one of my jsp page code and the error I am getting:
-----------
<html>
<head>
<title>Accessing data in a database</title>
</head>
<body>
<%@ page import="java.sql.* "%>
<%
try {
// Step 1. Load the JDBC driver
System.out.println("Getting there");
Class.forName("Sun.jdbc.odbc.JdbcOdbc.Driver");

// Step 2. Create a Connection object
Connection con = DriverManager.getConnection(
"jdbc dbc:Msql///CoreData/CoreData2000",
"budi", "secret");
System.out.println("got connection");


// Step 4. Use the same Statement object to obtain a ResultSet object
String sql = "SELECT * FROM Project";
Statement s= con.createStatement();;
ResultSet rs = s.executeQuery(sql);
while (rs.next()) {
out.println(rs.getString(1) + " " + rs.getString(2) + "<br>");
}
rs.close();
s.close();
con.close();
}
catch (ClassNotFoundException e1) {
// JDBC driver class not found, print error message to the console
System.out.println(e1.toString());
}
catch (SQLException e2) {
// Exception when executing java.sql related commands, print error message to the console
System.out.println(e2.toString());
}
catch (Exception e3) {
// other unexpected exception, print error message to the console
System.out.println(e3.toString());
}
%>
</body>
</html>

When I open my page through the localhost, the page is all blank and in my tomcat window I am having this error:
java.lang.ClassNotFoundException: Sun.jdbc.odbc.JdbcOdbc.Driver
Getting there
Can You please tell me why it's doing that or how to solve it. It's a access database in the Microsoft sql server, obdc
Thanks
 
Gloria Hans
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I had Sun.jdbc.odbc.JdbcOdbc.Driver instead of sun.jdbc.odbc.JdbcOdbcDriver
but now that I've fixed that, I am having this error in my tomcat window and my jps page is still blank:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
how do I specify the default driver? why my datasource is not found(odbc)?
please help
 
Ranch Hand
Posts: 38
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you set up the DSN from Data Sources (ODBC) in "Control Panel / Admin Tools" (in win2000/XP)
You can then simplify your datasource URL
see the set up here
http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html
Also try the JDBC forum on this site..
 
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gloria:
Your name does not conform with the naming convention(first name, last name). I advice you correct that before they lock up your post.
In response to your question I see this line jdbc dbc:Msql///CoreData/CoreData2000" in your code and I kind of wonder if that is where your database is located; Do you have a database located at Msql///CoreData/CoreData2000. I assume the name of your database to be CoreData2000 and I think that should have read "jdbc dbc:CoreData2000". I think your problem is coming from that line, assuming your access database is well set up.
Personally, I do not program Servlets with access database; I hope others who do will be able to contribute to this
anselm
 
Gloria Hans
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just added a last name initial on my displayed name. I hope that's enough. Thanks.
ok well, I am still having the same error I had last night. I went to my odbc window and created a dsn of my database.
My new code is:
************
<html>
<head>
<title>Accessing data in a database</title>
</head>
<body>
<%@ page import="java.sql.* "%>
<%
try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

System.out.println("Getting there");

Connection con = DriverManager.getConnection("jdbc: odbc:AccessCore");
System.out.println("got connection");


String sql = "SELECT * FROM Project";
Statement s= con.createStatement();;
ResultSet rs = s.executeQuery(sql);
while (rs.next()) {
out.println(rs.getString(1) + " " + rs.getString(2) + "<br>");
}
rs.close();
s.close();
con.close();
}
catch (ClassNotFoundException e1) {

System.out.println(e1.toString());
}
catch (SQLException e2) {

System.out.println(e2.toString());
}
catch (Exception e3) {

System.out.println(e3.toString());
}
%>
</body>
</html>
********
Note that the name of my dsn is accesscore. But the jps page is still blank and the error is the same on my tomcat window.
:roll: :roll: :roll: :roll:
I am trying not to use servlets this time but only jsp to connect to my database. The database is an access database but on a Microsoft sql server. Do you think it's not a good idea to use jsp? What the other options(the easiest)? an tutorial?
Please, urgent help needed.
GH
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Gloria!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your last name cannot be an initial.
Thanks!
bear
JSP Fourm Bartender
[ November 28, 2003: Message edited by: Bear Bibeault ]
 
Gloria Hans
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,
I wrote the name of my dsn wrong when creating the connection. Now I can connect to my database just fine. Thanks for those who helped but I have another question
I reading from my database and it's returning the data I need on my jsp page. But it's just too much data on one page. I want to be able to display only 20 rows data at a time and move the rest to the next page. How do I do that? I tried to do some research on google on page size, then number of rows, but i couldn't find anything that helped me.
I also want to be able to store a resultset into a string for me to have tables.
For example(this is wrong) :
String st="1C";
String sql = "SELECT * FROM Projects WHERE Status = '" +st+"'";
Statement s= con.createStatement();
ResultSet rs = s.executeQuery(sql);
String myString= rs.getString(1);
This last line gives me an error.
I wanna be able to do something like:
<tr>
<td>myString</td>
</td>
How do I get the rs.getString(1) to actually be a String???
THanks
 
Anselm Paulinus
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The last line is definitely going to give you an error.
Try something like while (rs.next()){
myString = rs.getString(1) ; // usually I prefer using the table column name here
}
As per pagination; do a search on it here.
 
reply
    Bookmark Topic Watch Topic
  • New Topic