Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

connecting to mysql from jsp  RSS feed

 
vamsee krishna
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i am new to jsp, i don't know how to connect to a mysql database from jsp. i have used jdbc.odbc.JdbcOdbc.Driver to connect to mysql from jsp, but i have got an error saying java.lang.noclassfound exception. but if i use same cade in a java program its working fine, pla help me out in connecting and accessing mysql from jsp.


<HTML>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<%
String s = request.getParameter("name");
out.println(s);
%>
<%
try
{
Class.forName("jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc dbc:iwad");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT name,address FROM usr");
while(rs.next())
{
out.println(rs.getString(1));
out.println(rs.getString(2));
}
}
catch(Exception e)
{
out.println("Exception:"+e);
}
%>

Thank u
satya
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satya,
It looks like the driver isn't in the classpath for your web application/app server.
 
Sarath Mohan
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

For my sql better use the driver used available in myql web site. If you are using tomcat web container keep the jar file in WEB-INF\lib directory of your web application. Sometimes it still may not work. Then put the same into <Tomcat Install-Dir>/commons/lib directory.
Definitely it will work. The JDBC url needs to be chnanged
jdbc:mysql://<databaseserver> ortnumber bname?user=<username>&password=<password>

Regards
Sarath
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!