Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ljava/lang/String Error Pls Help...

 
Jil Nautilus
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Im using a bean in a jsp to search a db and get results as a ResultSet.My bean is as below,

package MyBeans.CheckBeans;
import java.io.Serializable;
import java.sql.*;
import java.util.*;

public class SearchCustomer implements Serializable
{
Connection con;

public void connect()throws Exception
{
String Url = "jdbc:microsoft:sqlserver://192.169.100.1:1433;DatabaseName=SeaData";
String name = "myName";
String Pass = "myPassword";
String myDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";

Driver driver1 = (Driver)Class.forName(myDriver).newInstance();
con = DriverManager.getConnection(Url,name,Pass);

}

public void disconnect()throws Exception
{
if(con != null)
con.close();
}

public ResultSet searchByID(String ID)throws Exception
{
String custID = ID;
String query = "SELECT name,address FROM CustomerDetails WHERE "+
"customerID='"+custID+"'";

Statement stmt= con.createStatement();
ResultSet rs = stmt.executeQuery(query);

return rs;

}

public ResultSet searchByName(String name)throws Exception
{
String custName = name;
String query = "SELECT name,address FROM CustomerDetails WHERE "+
"Name LIKE '" +custName+ "%'";

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

return rs;

}

public ResultSet searchByAddress(String address)throws Exception
{
String custAddress = address;
String query = "SELECT name,address FROM CustomerDetails WHERE "+
"Address LIKE '"+custAddress+"%'";

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

return rs;
}

public int getSize(ResultSet rs)throws Exception
{
ResultSet res = rs;
int rsSize = -1;

// count the total records by iterating through the resultset
for (rsSize = 1; rs.next(); rsSize++);

rs.close();

return rsSize;
}

public ResultSet searchMeBy(String val,String cri)throws Exception
{
String searchVal = val;
String searchCri = cri;
ResultSet rs;

if(searchCri.compareToIgnoreCase("custID") == 0)
{
rs = searchByID(searchVal);
}

else if(searchCri.compareToIgnoreCase("custName") == 0)
{
rs = searchByName(searchVal);
}

else if(searchCri.compareToIgnoreCase("custAddress") == 0)
{
rs = searchByAddress(searchVal);
}

else
{
rs = null;
}

return rs;

}



}

Im trying to use searchMeBy to direct the user request in to the appropriate method as u can c.

all the other methods are working properly except searchMeBy and getSize methods.

When I try to use the searchMeBy method Ive got an error as

java.lang.NoSuchMethodError: MyBeans.CheckBeans.SearchCustomer.searchMeBy(Ljava/lang/String;Ljava/lang/String ;) Ljava/sql/ResultSet;

Then Ive removed the searchMeBy method and try to use getSize method but then got an error as

java.lang.NoSuchMethodError: MyBeans.CheckBeans.SearchCustomer.getSize(Ljava/sql/ResultSet ;) I

my IDE ---> is JCreator Pro 3.10.008
Java v ---> j2sdk1.4.2
OS ---> WinXP

Pls help me on this.
Thanx in advance for any help.
Best regs,
Jil

[ June 27, 2004: Message edited by: Ernest Friedman-Hill ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting an error message like this at runtime means that the class you compiled your code against is not the same one you're running against; these methods appear in your source code, but the .class file that the running application picks up is an older one that doesn't have these methods.

Check your runtime CLASSPATH, and search around for multiple copies of the searchCustomer class. Delete every copy you can find. Then recompile your app and try again.
 
Jil Nautilus
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Ernest,
When I remove all those if statements in this method and write it like

public ResultSet searchMeBy(String val,String cri)throws Exception
{
String searchVal = val;
String searchCri = cri;
ResultSet rs=null;

return rs;

}
my jsp can identify this method.But when I put those if statements back its giving me the same error.There are no duplicate class files and if so there wont be something like I said above, isnt it?
By the way ,Thanx again for your support.
best regs,
Jil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic