Posted By:
shrikumar_hegde
Posted On:
Tuesday, December 16, 2008 07:39 AM
Jlogincode page i created my bean program like this package mybeans; import java.sql.*; /** * * @author ShriKumar */ public class DbCon { private Connection con=null; private Statement st = null; private ResultSet rs=null; int i=0; public DbCon() { try { Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e) { System.out.println("Error found in jdbc connection "+e); } } public void mkcon() { try { con=DriverManager.getConnection("jdbc:mysql://localhost:3306/adept?user=shrikumar&am
More>>
Jlogincode page
i created my bean program like this
package mybeans;
import java.sql.*;
/**
*
* @author ShriKumar
*/
public class DbCon
{
private Connection con=null;
private Statement st = null;
private ResultSet rs=null;
int i=0;
public DbCon()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e)
{
System.out.println("Error found in jdbc connection "+e);
}
}
public void mkcon()
{
try
{
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/adept?user=shrikumar&password=shrikumar");
}
catch(Exception e)
{
System.out.println("Error in UserID");
}
}
public int insert(String str)
{
try
{
i=st.executeUpdate(str);
}
catch(Exception e)
{
System.out.println("invalid Update");
}
return(i);
}
public ResultSet fetch(String str) throws SQLException
{
try
{
rs=st.executeQuery(str);
}
catch(NullPointerException e)
{
e.printStackTrace();
//System.out.println("timmaya problem is here "+e);
}
return(rs);
}
}
i didn't create any setter and getter method because i need this bean in all jsp fils
and i written a jsp page like this
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import ="java.io.*,java.sql.*" %>
"http://www.w3.org/TR/html4/loose.dtd">
<%
db.mkcon();
String User = request.getParameter("ID");
String Pass = request.getParameter("password");
System.out.println("userId "+User+" password "+Pass);
String shri="select * from verify where userId='"+User+"' and password='"+Pass+"'";
ResultSet rs = db.fetch(shri);
if (rs.next()) {
%>
//
success
<%} else {
%>
invalid ID or Password
<% }
%>
i am using netbean IDE 6.5
but if i going to run this jsp file.. i am getting NullPointException..
i tried almost all method..even mySql is working fine if i code all these in servlet code..
previously i worked with ms access with myeclipse..
i was working properly un der..
but it is not working in here..
please send me solution..