This is my code and i placed it in WEB-INF/classes/SQLBean/DbBean.java,Dbbean.class
CODE
package SQLBean;
import java.sql.*;
import java.io.*;
public class DbBean
{
private Connection dbCon;
public DbBean()
{
super();
}
public boolean connect() throws ClassNotFoundException,SQLException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbCon = DriverManager.getConnection("Jdbc:Odbc:library","jairam","ray");
return true;
}
public void close() throws SQLException
{
dbCon.close();
}
public ResultSet execSQL(String sql) throws SQLException
{
Statement s = dbCon.createStatement();
ResultSet r = s.executeQuery(sql);
return (r == null) ? null : r;
}
public int updateSQL(String sql) throws SQLException
{
Statement s = dbCon.createStatement();
int r = s.executeUpdate(sql);
return (r == 0) ? 0 : r;
}
}
And this is JSP code and i M trying to call the connection
<%@ page language="Java" import="java.sql.*" %>
<jsp:useBean id="db" scope="page" class="SQLBean.DbBean" />
<jsp:setProperty name="db" property="*" />
<%!
ResultSet rs = null;
String name="";
%>
<center>
<h2> Results from </h2>
<hr>
<br><br>
<table>
<%
db.connect();
try
{
rs = db.execSQL("select * from addbook");
}
catch(Exception ex)
{
out.println("Error"+ex.getMessage());
}
%>
<%
while(rs.next())
{%>
<%=rs.getString("name")%>
<% }
%>
<br>
<%
db.close();
%>
***added code tags***
--jjsaw5