aspose file tools*
The moose likes JDBC and the fly likes Select statement not working in Java Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Select statement not working in Java Bean" Watch "Select statement not working in Java Bean" New topic
Author

Select statement not working in Java Bean

jan mohammad kalla
Greenhorn

Joined: Mar 20, 2013
Posts: 2
Problem:
Select statement in below java bean is not working

Program Control stops at select statements that i have used at two places...



package ums;
import java.sql.*;
import connect.Conection;
import javax.servlet.jsp.JspWriter;
/**
*
* @author HAMAD
*/
public class Feedback
{

JspWriter out;
Connection c=Conection.getConnection();
String name="name";
String user="user", email="email", query="query";
int qid=0;

public void setName(String name)
{
if(!name.equals(null))
this.name=name;
}

public void setUser(String user)
{
if(!user.equals(null))
this.user=user;
}

public void setEmail(String email)
{
if(!email.equals(null))
this.email=email;
}

public void setQuery(String query)
{
if(!query.equals(null))
this.query=query;
}

public void setQid(String qid)
{
if(!qid.equals(null))
this.qid=Integer.parseInt(qid);
}


public void setOut(JspWriter out)
{
this.out=out;
}

public String submitQuery()
{
try
{
PreparedStatement ps=null;
ResultSet rs=null;
Statement st=null;

if(name.equals("name"))
{
}

if(name.equals("SUBMIT"))
{
String ans="Pending for Reply";
int qid=0;
/* int qid1=1;
out.println("Testing!!!");
rs=st.executeQuery("select qid from Query");
out.println("Testing!!!");
while(rs.next())
{
qid1=rs.getInt(1);
}
qid1=qid1+1;
*/
ps=c.prepareStatement("insert into Query (uname, email, query, answer) values(?,?,?,?)");
// ps.setInt(1,qid1);
ps.setString(1,user);
ps.setString(2,email);
ps.setString(3,query);
ps.setString(4,ans);

int i=ps.executeUpdate();
out.println("i= "+i);

rs=st.executeQuery("select qid from Query where email='"+email+"'");
out.println("Testing!!!");
while(rs.next())
{
qid=rs.getInt(1);
}


if(i==1)
{

out.println("Query Submitted!!!
Your query id is "+qid+"
Note your query id for further reference.");
}
else
out.println("Failed to submit your query!!!
Please try again.");
}


if(name.equals("VIEW"))
{
rs=st.executeQuery("select * from Query where qid="+this.qid+"");
out.println("Testing!!!");

out.println(""); out.println(""); while(rs.next()) { out.println(""); } out.println("
qidNameQueryAnswer
"+rs.getInt(1)+""+rs.getString(2)+""+rs.getString(4)+""+rs.getString(5)+"
");
}

}
catch(Exception e)
{

}
return "xx";
}

}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Select statement not working in Java Bean