PDA

View Full Version : i am suffering from this problem from last 10 days can any one help me



janunme
04-10-2007, 07:12 PM
hi to all


i am not able to solve this problem from last 10 days. i wnat to access records from mysql database and with jsp( all JDBC code written inside jsp program) it is working. now my problem is i want to write JDBC code into .class files using package concept but i am failing there itself. i got struck from last 10 days at that place only.

i am including my code

connect.java
-----------------


package connection;
import java.sql.DriverManager;
import java.sql.Connection;
import java.io.*;
public class connect
{
Connection conn;
public connect()
{
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e)
{
System.out.println(e);
}
}
public Connection getConnection()
{
try{
conn=DriverManager.getConnection("mysql:mysql://localhost/hello","root","root");
}catch(Exception e)
{
System.out.println(e);
}
return conn;
}
}

------------------

SqlBean.java
----------------


package sq;

import connection.*;
import java.sql.*;

public class SqlBean
{
Connection con=null;

public SqlBean()
{
connect c=new connect();
con=c.getConnection();
}

// it is used to select the records based on Query
public ResultSet selection(String query)
{
ResultSet rs=null;
*try
{
Statement st=con.createStatement();
rs=st.executeQuery(query);
//return rs;
}
catch(Exception e)
{
System.out.println(e);
}

return rs;
}
}


and my jsp code is




<%@ page import="java.sql.*" session="false" %>
<jsp:useBean id="sq" class="sql.SqlBean" scope="page" />
<%! int id;%>
<% String str1="select * from countmast";
ResultSet rs=sq.select(str1);
while (rs.next())
{
id=rs.getInt(1);
out.println(id);
}
%>

---------------------

i amgetting the following exception



"exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.NullPointerException
org.apache.jsp.test_jsp._jspService(test_jsp.java:57)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)"


can any one help me to come out from this problem. becoz it is eating my time like any thing

regards