-1

I am using smart fox server.where i connecting this server to My sql database.

This query is properly running in My sql command line but when i writing this query in server side getting error.i know error is in % emp_id% .Here emp_id is constant. I am trying in such a way but still getting error.

String sql="
SELECT emp_first_name
     , emp_last_name
     , msg_title
     , msg_body 
  FROM message_master 
  JOIN emp_master 
    ON emp_master.emp_id = message_master.empmsgsender_id 
   AND message_master.emp_id IN(SELECT emp_id 
                                  FROM message_master 
                                 WHERE emp_id LIKE %'"+emp_id+"'%)";

   @Override
public void handleClientRequest(User user, ISFSObject isfso) 
{
try
{
    trace("within request for message");
    String emp_id=isfso.getUtfString("uid");
    trace( "Employee_id:"+emp_id);

//    String sql="SELECT emp_first_name,emp_last_name,msg_title,msg_body from message_master inner join emp_master ON emp_master.emp_id=message_master.empmsgsender_id AND message_master.emp_id='"+emp_id+ "' LIMIT 10";
    String sql="SELECT emp_first_name,emp_last_name,msg_title,msg_body from message_master inner join emp_master ON emp_master.emp_id=message_master.empmsgsender_id AND message_master.emp_id IN(SELECT emp_id from message_master where emp_id LIKE %emp_id%)";
    trace("After sql query");
    sfsdb=getParentExtension().getParentZone().getDBManager();
    conn=sfsdb.getConnection();
    trace("connection established");
    ps=conn.prepareStatement(sql);
    rs=ps.executeQuery();

    trace("After resultset");
Strawberry
  • 33,750
  • 13
  • 40
  • 57
Rims Sharma
  • 221
  • 1
  • 2
  • 9

1 Answers1

0

I'm confused. How does that query differ from this one...

String sql="
SELECT emp_first_name
     , emp_last_name
     , msg_title
     , msg_body 
  FROM message_master m
  JOIN emp_master e
    ON e.emp_id = m.empmsgsender_id 
 WHERE m.empid LIKE '%emp_id%'; -- and why are you using `LIKE`???
 "; 

(This isn't an answer, but I wanted to take advantage of formatting options)

Strawberry
  • 33,750
  • 13
  • 40
  • 57
  • emp_id is constant...when i use this syntax emp_id is consider as a string....which is wrong – Rims Sharma Feb 03 '14 at 12:09
  • So why use LIKE at all? `empid = constant_in_smartfoxserver_format` – Strawberry Feb 03 '14 at 12:11
  • String sql="SELECT emp_first_name,emp_last_name,msg_title,msg_body from message_master inner join emp_master ON emp_master.emp_id=message_master.empmsgsender_id AND message_master.emp_id IN(SELECT emp_id from message_master where emp_id LIKE " + "\"%" + emp_id + "%\")"; actully i got the answer....thanx friends – Rims Sharma Feb 03 '14 at 12:15
  • Yeah, whatever... ;-) – Strawberry Feb 03 '14 at 12:16