Pawan Sinha

Greenhorn
+ Follow
since Jan 16, 2001
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pawan Sinha

string str= new String("Pawan") creates a new memory space for string str, so if u will equate the two string variables declared as in yr query, the result will be false as these two string variable are having diffrent reference.
21 years ago
1.Servlets are faster than CGI-Perl Scrips
2.Servlets works on threads whereas cgi works on processes
3.Servlets are portable, Cgis are not.

If u want to know more about it. Write Servlets+advantages in google search. U will the thousands of pages , The first two or three pages willserve the purpose
Bye
Pawan
21 years ago
Do u know after setting the autoexec.bat file u have to restart the computer or run autoexec.The other solution is set the classpath directly from the dos prompt.Write the command
set classpath="%classpath%;JWS.../lib/jsdk.jar". Probably this will help you.
21 years ago
If you are having Jsdk loaded in your machine, you can run your servlets.First of all set path to jdk\bin directory and also jsdk\bin directory, then start servletrunner utility.Then write http://localhost:8080/Servlet/Myservlet in your browser adress bar.Write me back if you are still having problems.
[This message has been edited by Pawan Sinha (edited February 06, 2001).]
21 years ago
I dont think there should be any problem. You just add the date fields with required number of months,and insert into the database.I think the error is in the database.
By the way what error you are getting.Is there any problem in database connetivity
21 years ago
Thanks for reply.I am fetching the data through HTML forms, So the data is being entered by the user and the servlet should put up the result on front end...Am I right.So why null pointer exception.
Leave that even if u explicitly assign the values of the parameters, null pointer exception comes even in that case ..
Thanks in Advance for reply
21 years ago
It gives Null pointer Exception in Runtime that is when we run it through html page.. please guide me whats wrong
21 years ago
Here is a source code for searching of some terms in database,First of all please tell me the differece between using
class.forname and DriverManager.registerDriver.When I use this code with proper initialization it executes twice but after that it terminates.pLease tell me whats wrong with this,I am new to servlets so please excuse me if this sounds odd.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import sun.jdbc.odbc.*;

public class SearchPage extends HttpServlet{

Connection dbCon;

public void init() throws ServletException{



try{



Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbCon=DriverManager.getConnection("jdbc dbc:test");
DriverManager.registerDriver(new JdbcOdbcDriver());
dbCon=DriverManager.getConnection("jdbc dbc:test");
}
catch(ClassNotFoundException e)
{
System.out.println("Test:database driver ccould not be found");
System.out.println(e.toString());
throw new UnavailableException(this,"Database driver class not found");
}
catch(SQLException e)
{
System.out.println("Error connecting to the database");
System.out.println(e.toString());
throw new UnavailableException(this,"Cannot connect to the database");

}

}

public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException{

/*try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbCon=DriverManager.getConnection("jdbc dbc:test");

}
catch(ClassNotFoundException e)
{
System.out.println("Test:database driver ccould not be found");
System.out.println(e.toString());
throw new UnavailableException(this,"Database driver class not found");
}
catch(SQLException e)
{
System.out.println("Error connecting to the database");
System.out.println(e.toString());
throw new UnavailableException(this,"Cannot connect to the database");

}*/

/*try{
DriverManager.registerDriver(new JdbcOdbcDriver());
dbCon=DriverManager.getConnection("jdbc dbc:test");
}
catch(SQLException e)
{
System.out.println("Error connecting to the database");
System.out.println(e.toString());
throw new UnavailableException(this,"Cannot connect to the database");

}*/
ResultSet rs;
Statement stmt;
StringBuffer qry=new StringBuffer(1024);
int numCriteria=0;
String name="pawan";
String zip="831001";
String speciality="java";
String money="4000";
res.setContentType("text/html");
PrintWriter out=res.getWriter();
name=req.getParameter("txtName");
speciality=req.getParameter("txtSpeciality");
zip=req.getParameter("txtZip");
money=req.getParameter("txtMoney");
qry.append("SELECT fname,speciality,money_range FROM Table1 WHERE");


if(name.length()>0){
qry.append(" fname LIKE '%");
qry.append(name);
qry.append("%' AND");
numCriteria++;
}
if(zip.length()>0){
qry.append(" zip LIKE '%");
qry.append(zip);
qry.append("%' AND");
numCriteria++;
}
if(speciality.length()>0){
qry.append(" speciality LIKE '%");
qry.append(speciality);
qry.append("%' AND");
numCriteria++;
}

if(money.length()>0){
qry.append(" money_range LIKE '");
qry.append(money);
qry.append("' AND");
numCriteria++;
}


if(numCriteria>0)
{
qry.delete(qry.length()-3,qry.length());
}else{
qry.delete(qry.length()-5,qry.length());
}

try{
stmt=dbCon.createStatement();
rs=stmt.executeQuery(qry.toString());
}catch(SQLException e)
{
res.sendError(res.SC_ACCEPTED,"The request hasbeen accepted ,but it failed to complete due to a problem in quering the database.");
return;
}

HTML h=new HTML("Search Results");
h.add(HTML.HEADING,"Selected results",true);
h.add(HTML.LINE," ",false);

String labels[]={"Name" ,"Speciality","Money Range"};

if(!h.addTable(labels,rs)){
res.sendError(res.SC_ACCEPTED,"The request hasbeen accepted but it failed to complete due to problem accessing the data.");
return;
}

out.println(h.getPage());
out.close();
}

public void destroy(){
try{
dbCon.close();
}catch(Exception e)
{
System.out.println("Test atabase close failed");
System.out.println(e.toString());
}
}
public class HTML
{
public static final int NORMAL=0;
public static final int HEADING=1;
public static final int LINE=2;
public StringBuffer buffer;

public HTML(String title)
{
buffer=new StringBuffer(4096);
this.buffer.append("<HTML><HEAD><TITLE>");
this.buffer.append(title);
this.buffer.append("</TITLE></HEAD><BODY>");
}
public void add(int style,String text,boolean linebreak)
{
switch(style)
{

case NORMAL:
this.buffer.append(text);
break;
case HEADING:
this.buffer.append("<H1>");
this.buffer.append(text);
this.buffer.append("</H1>");
break;
case LINE:
this.buffer.append("<HR>");
break;
default:
break;
}
if(linebreak)
{
buffer.append("<BR>");
}
}

public String getPage()
{
this.buffer.append("</BODY></HTML>");
return this.buffer.toString();
}
public boolean addTable(String labels[],ResultSet rs)
{
int cols=labels.length;
this.buffer.append("<TABLE WIDTH='100%'>");
this.buffer.append("<TR>");

for(int i=0;i<cols;i++){
this.buffer.append("<TH ALIGN='left'>");
this.buffer.append(labels[i]);
this.buffer.append("</TH>");
}
this.buffer.append("</TR>");

try{
while(rs.next()){

this.buffer.append("<TR>");
for(int i=1;i<=cols;i++){
this.buffer.append("<TD>");
this.buffer.append(rs.getString(i));
this.buffer.append("</TD>");
}

this.buffer.append("</TR>");
}

}catch(SQLException e)
{
return false;
}

this.buffer.append("</TABLE>");
return true;
}


}
}




21 years ago
I am new in this site, same question I had asked a few days back,albeit no one replied, Through previous discussions, I concluded that now a days java market is slightly down, but it is not that it will be so for ever, still there is a huge demand of java professional.Java is not a small thing, You can do a lot in java.I have 2 and half years experience in java, and u know whereever I apply I get call for interview with almost 90% strike rate.Many companies emphasize on tel. interview also.So I dont think that java market will go down in near future.Ranchites correct me if I am wrong
21 years ago
I have worked in Oracle and developer 2000 and from last 1.5 years I am working in java platform mostly on servlets.I am in a Steel industry and now I immediately want to shift in a hard core software industry, as growth as a software professional is very stagnant in this industry.I just want to know what is the future in java.Where should I apply
21 years ago