salasadi
asked on
I want to get 16 digit number from Oracle but I get error
I am using tomcat/JDBC to access Oracle.
public int getNumber()
throws MyException
{
Connection connection = null;
MyException exception = null;
Statement statement = null;
ResultSet rs = null;
long CustNum = 0;
try
{
connection = DBConnection.getConnection ();
statement = connection.createStatement ();
String CardNum = "select CustID from evisa where ACCOUNT=208487";
rs = statement.executeQuery(Car dNum);
if(rs.next())
{
CustNum = rs.getLong("CustID");
System.out.println(CustNum );
}
}
catch(SQLException sqle)
{
exception = new MyException(HBError.get("D atabaseFai lure.exCod e"), HBError.get("DatabaseFailu re.exDescr iption"), HBError.get("DatabaseFailu re.exRecov ery"), sqle);
}
finally
{
DBConnection.freeConnectio n(connecti on, statement, null);
if(exception != null)
throw exception;
}
return CustNum;
}
I am getting error:
java.sql.SQLException: Numeric Overflow
becuase the CustID is long number (16 digits) and. I chnage my test account to be # 10 then my code worked. I know my problem is the lrage number.
I tried to make int to Long I get an error:
found : long
required: int
return CustNum;
^
1 error
how can I solve this problem
thanks
public int getNumber()
throws MyException
{
Connection connection = null;
MyException exception = null;
Statement statement = null;
ResultSet rs = null;
long CustNum = 0;
try
{
connection = DBConnection.getConnection
statement = connection.createStatement
String CardNum = "select CustID from evisa where ACCOUNT=208487";
rs = statement.executeQuery(Car
if(rs.next())
{
CustNum = rs.getLong("CustID");
System.out.println(CustNum
}
}
catch(SQLException sqle)
{
exception = new MyException(HBError.get("D
}
finally
{
DBConnection.freeConnectio
if(exception != null)
throw exception;
}
return CustNum;
}
I am getting error:
java.sql.SQLException: Numeric Overflow
becuase the CustID is long number (16 digits) and. I chnage my test account to be # 10 then my code worked. I know my problem is the lrage number.
I tried to make int to Long I get an error:
found : long
required: int
return CustNum;
^
1 error
how can I solve this problem
thanks
ASKER
so leave everything as is but change this line or make the variable as long in my decalration?
Try
BigDecimal CustNum = rs.getBigDecimal("CustID") ;
BigDecimal CustNum = rs.getBigDecimal("CustID")
ASKER
now I am getting this:
found : java.math.BigDecimal
required: int
return CCustNum;
Thanks
found : java.math.BigDecimal
required: int
return CCustNum;
Thanks
Well, obviously you'd have to *return* BigInteger instead
ASKER
when I did that I get the following:
found : java.math.BigDecimal
required: java.math.BigInteger
return (BigInteger) CustNum;
^
when I remove the ()
I get the following:
C:\com\test\getNumber.java :51: ';' expected
return BigInteger CardAcctNum;
found : java.math.BigDecimal
required: java.math.BigInteger
return (BigInteger) CustNum;
^
when I remove the ()
I get the following:
C:\com\test\getNumber.java
return BigInteger CardAcctNum;
ASKER
woops
it retruns return BigInteger CustNum; sorry for the typo
it retruns return BigInteger CustNum; sorry for the typo
> public int getNumber()
change that to
public BigInteger getNumber()
change that to
public BigInteger getNumber()
ASKER
I did that but still
ASKER
now I am getting this error:
C:\com\test\getNumber.java :52: inconvertible types
found : java.math.BigDecimal
required: java.math.BigInteger
return (BigInteger) CustNum;
^
C:\com\test\getNumber.java
found : java.math.BigDecimal
required: java.math.BigInteger
return (BigInteger) CustNum;
^
Don't forget
BigInteger CustNum = null;
as well
BigInteger CustNum = null;
as well
ASKER
some it compliants about coverting the variable! even after I intil the BigInteger CustNum = null;
C:\com\test\getNumber.java :52: inconvertible types
Thanks
C:\com\test\getNumber.java
Thanks
There should be no conversion. Get rid of int altogether
Try to cast to int:
public int getNumber(){
...
return CustNum.intValue();
}
Bye, Giant.
public int getNumber(){
...
return CustNum.intValue();
}
Bye, Giant.
if you need you can even use:
CustNum.floatValue()
or
CustNum.longValue()
...
See http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html
CustNum.floatValue()
or
CustNum.longValue()
...
See http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html
ASKER
Giant,
Thanks the casting did it. I still have 1 problem. some time CustNum retrun more then one value, and I need to pass the values to JSP page:
Myclass test = new myclass();
String CustNum = String.valueOf(test.getCus tNumber()) ;
husband and wife can both have the same account but diffrent Custnum, I need to get both custnum and give them the option to select which account to view.
Thanks again
Thanks the casting did it. I still have 1 problem. some time CustNum retrun more then one value, and I need to pass the values to JSP page:
Myclass test = new myclass();
String CustNum = String.valueOf(test.getCus
husband and wife can both have the same account but diffrent Custnum, I need to get both custnum and give them the option to select which account to view.
Thanks again
>>Thanks the casting did it.
How are you casting? int cannot hold the maximum 16 digit number
int i = 9999999999999999; // Won't compile
How are you casting? int cannot hold the maximum 16 digit number
int i = 9999999999999999; // Won't compile
ASKER
I left the BigDecimal when I get the rs:
CustNum = rs.getBigDecimal("CustNum" );
I cheange the retrun value to :
return CustNum.intValue();
the output:
5194820009999090
CustNum = rs.getBigDecimal("CustNum"
I cheange the retrun value to :
return CustNum.intValue();
the output:
5194820009999090
You must change this piece of code:
if(rs.next())
{
CustNum = rs.getLong("CustID");
System.out.println(CustNum );
}
}
make a while cycle. In this manner you read all the record from your ResultSet.
After this the return variable of your method must be an array or a collection (Vector).
if(rs.next())
{
CustNum = rs.getLong("CustID");
System.out.println(CustNum
}
}
make a while cycle. In this manner you read all the record from your ResultSet.
After this the return variable of your method must be an array or a collection (Vector).
ASKER
can you give anexample please. I still have a hard time to understand OO
Example:
public Vector getNumber(){
Vector ret=new Vector();
...
while (rs.next()){
CustNum=rs.getBigDecimal(" CustNum");
System.out.println(CustNum );
ret.addElement(CustNum);
}
return ret;
}
Be sure that when you call this method you must cast correctly the element of the Vector.
Example:
Vector numbers=getNumber();
int value0=((BigDecimal)number s.elementA t(0)).intV alue;
public Vector getNumber(){
Vector ret=new Vector();
...
while (rs.next()){
CustNum=rs.getBigDecimal("
System.out.println(CustNum
ret.addElement(CustNum);
}
return ret;
}
Be sure that when you call this method you must cast correctly the element of the Vector.
Example:
Vector numbers=getNumber();
int value0=((BigDecimal)number
>>
I cheange the retrun value to :
return CustNum.intValue();
>>
But you can't do that - that number will not fit in an int. See the following:
BigInteger bi = new BigInteger("51948200099990 90");
System.out.println(bi.intV alue());
System.out.println(bi);
I cheange the retrun value to :
return CustNum.intValue();
>>
But you can't do that - that number will not fit in an int. See the following:
BigInteger bi = new BigInteger("51948200099990
System.out.println(bi.intV
System.out.println(bi);
Or, example 2:
public int[] getNumber(){
Vector ret=new Vector();
..
while (rs.next()){
CustNum=rs.getBigDecimal(" CustNum");
System.out.println(CustNum );
ret.addElement(CustNum);
}
int[] retint=int[ret.size()];
for (int i=0;i<ret.size();i++){
retint[i]=((BigDecimal)ret .elementAt (i)).intVa lue();
}
return retint;
}
In this manner you can manage the int value "directly".
int[] values=getNumber();
Is it clear now?
Hope this could help you.
Bye, Giant.
public int[] getNumber(){
Vector ret=new Vector();
..
while (rs.next()){
CustNum=rs.getBigDecimal("
System.out.println(CustNum
ret.addElement(CustNum);
}
int[] retint=int[ret.size()];
for (int i=0;i<ret.size();i++){
retint[i]=((BigDecimal)ret
}
return retint;
}
In this manner you can manage the int value "directly".
int[] values=getNumber();
Is it clear now?
Hope this could help you.
Bye, Giant.
ASKER
C:\com\test\getnumber.java :15: illegal start of expression
public int[] getNumber()
^
public int[] getNumber()
^
check the { } parentesis. Maybe someone is not closed.
It would be more helpful if you post your entire code.
>> illegal start of expression
You have probably written that outside a class or inside a method.
>> illegal start of expression
You have probably written that outside a class or inside a method.
>>retint[i]=((BigDecimal)r et.element At(i)).int Value();
You *can't* do that, for the reason i stated
You *can't* do that, for the reason i stated
ASKER
public class getNumber
{
public getNumber()
{
public int[] getNumber()
{
Vector ret=new Vector();
throws MyException
{
Connection connection = null;
MyException exception = null;
Statement statement = null;
ResultSet rs = null;
BigDecimal CardAcctNum= null;
try
{
connection = DBConnection.getConnection ();
statement = connection.createStatement ();
String CardNum = "select Custnum from evisa where ACCOUNT=208487";
rs = statement.executeQuery(Car dNum);
while (rs.next())
{
CardAcctNum=rs.getBigDecim al("Custnu m");
System.out.println(CardAcc tNum);
ret.addElement(CardAcctNum );
}
catch(SQLException sqle)
{
exception = new MyException(HBError.get("D atabaseFai lure.exCod e"), HBError.get("DatabaseFailu re.exDescr iption"), HBError.get("DatabaseFailu re.exRecov ery"), sqle);
}
finally
{
DBConnection.freeConnectio n(connecti on, statement, null);
if(exception != null)
throw exception;
}
return ret;
}
}
}
{
public getNumber()
{
public int[] getNumber()
{
Vector ret=new Vector();
throws MyException
{
Connection connection = null;
MyException exception = null;
Statement statement = null;
ResultSet rs = null;
BigDecimal CardAcctNum= null;
try
{
connection = DBConnection.getConnection
statement = connection.createStatement
String CardNum = "select Custnum from evisa where ACCOUNT=208487";
rs = statement.executeQuery(Car
while (rs.next())
{
CardAcctNum=rs.getBigDecim
System.out.println(CardAcc
ret.addElement(CardAcctNum
}
catch(SQLException sqle)
{
exception = new MyException(HBError.get("D
}
finally
{
DBConnection.freeConnectio
if(exception != null)
throw exception;
}
return ret;
}
}
}
ASKER
sorry guys, here is the correct code:
public class getNumber
{
public getNumber()
{
public int[] getCustnum()
{
Vector ret=new Vector();
throws MyException
{
Connection connection = null;
MyException exception = null;
Statement statement = null;
ResultSet rs = null;
BigDecimal CardAcctNum= null;
try
{
connection = DBConnection.getConnection ();
statement = connection.createStatement ();
String CardNum = "select Custnum from evisa where ACCOUNT=208487";
rs = statement.executeQuery(Car dNum);
while (rs.next())
{
CardAcctNum=rs.getBigDecim al("Custnu m");
System.out.println(CardAcc tNum);
ret.addElement(CardAcctNum );
}
catch(SQLException sqle)
{
exception = new MyException(HBError.get("D atabaseFai lure.exCod e"), HBError.get("DatabaseFailu re.exDescr iption"), HBError.get("DatabaseFailu re.exRecov ery"), sqle);
}
finally
{
DBConnection.freeConnectio n(connecti on, statement, null);
if(exception != null)
throw exception;
}
return ret;
}
}
}
public class getNumber
{
public getNumber()
{
public int[] getCustnum()
{
Vector ret=new Vector();
throws MyException
{
Connection connection = null;
MyException exception = null;
Statement statement = null;
ResultSet rs = null;
BigDecimal CardAcctNum= null;
try
{
connection = DBConnection.getConnection
statement = connection.createStatement
String CardNum = "select Custnum from evisa where ACCOUNT=208487";
rs = statement.executeQuery(Car
while (rs.next())
{
CardAcctNum=rs.getBigDecim
System.out.println(CardAcc
ret.addElement(CardAcctNum
}
catch(SQLException sqle)
{
exception = new MyException(HBError.get("D
}
finally
{
DBConnection.freeConnectio
if(exception != null)
throw exception;
}
return ret;
}
}
}
You need to declare your method as
public Vector getNumber()
public Vector getNumber()
>> public getNumber()
>> {
>> public int[] getCustnum()
>> {
You cannot have a method inside a method like I said earlier. Perhaps just remove the public int[] getCustnum () and { after it, and also one } in the end. Plus make your method public getNumber () as public Vector getNumber ()
>> {
>> public int[] getCustnum()
>> {
You cannot have a method inside a method like I said earlier. Perhaps just remove the public int[] getCustnum () and { after it, and also one } in the end. Plus make your method public getNumber () as public Vector getNumber ()
ASKER
I am getting the following error:
C:\com\test\getNumber.java :15: illegal start of expression
throws MyException
^
here is my final version of the class
public class getNumber
{
public Vector getCustNumber()
{
Vector ret=new Vector();
throws MyException
{
Connection connection = null;
MyException exception = null;
Statement statement = null;
ResultSet rs = null;
BigDecimal CardAcctNum= null;
try
{
connection = DBConnection.getConnection ();
statement = connection.createStatement ();
String CustNum = "select Custnum from evisa where ACCOUNT=208487";
rs = statement.executeQuery(Cus tNum);
while (rs.next())
{
CustNum=rs.getBigDecimal(" Custnum");
System.out.println(CustNum );
ret.addElement(CustNum);
}
}
catch(SQLException sqle)
{
exception = new MyException(HBError.get("D atabaseFai lure.exCod e"), HBError.get("DatabaseFailu re.exDescr iption"), HBError.get("DatabaseFailu re.exRecov ery"), sqle);
}
finally
{
DBConnection.freeConnectio n(connecti on, statement, null);
if(exception != null)
throw exception;
}
}
return ret;
}
}
C:\com\test\getNumber.java
throws MyException
^
here is my final version of the class
public class getNumber
{
public Vector getCustNumber()
{
Vector ret=new Vector();
throws MyException
{
Connection connection = null;
MyException exception = null;
Statement statement = null;
ResultSet rs = null;
BigDecimal CardAcctNum= null;
try
{
connection = DBConnection.getConnection
statement = connection.createStatement
String CustNum = "select Custnum from evisa where ACCOUNT=208487";
rs = statement.executeQuery(Cus
while (rs.next())
{
CustNum=rs.getBigDecimal("
System.out.println(CustNum
ret.addElement(CustNum);
}
}
catch(SQLException sqle)
{
exception = new MyException(HBError.get("D
}
finally
{
DBConnection.freeConnectio
if(exception != null)
throw exception;
}
}
return ret;
}
}
>>throws MyException
should come directly after
>>public Vector getCustNumber()
should come directly after
>>public Vector getCustNumber()
ASKER
you mean it should look like this:
public Vector getCustNumber()
Vector ret=new Vector();
throws MyException
{
{
public Vector getCustNumber()
Vector ret=new Vector();
throws MyException
{
{
public Vector getCustNumber() throws MyException
ASKER
yaeeeeeeeeeee, the class is compiled successfully and ready to be test it. thank you guys for your help.
how can call vector from JSP?
before the vector I have the following:
Myclass test = new myclass();
String CustNum = String.valueOf(test.getCus tNumber()) ;
now I changed this to be:
static Vector keyw = new Vector(number);
how can call vector from JSP?
before the vector I have the following:
Myclass test = new myclass();
String CustNum = String.valueOf(test.getCus
now I changed this to be:
static Vector keyw = new Vector(number);
In your JSP you need to do
<%
Vector v = new getNumber().getCustNumber( );
// Now use it
%>
Incidentally, class names should begin with a capital letter or your code gets hard to read
<%
Vector v = new getNumber().getCustNumber(
// Now use it
%>
Incidentally, class names should begin with a capital letter or your code gets hard to read
ASKER
you mean getNumber should be GetNumber? This is how I design my code in VB and ASP, someone told me that in Java the standard is to use small letter for the first letter of variable and class, but the second word in the name should be Uppercase.
No. In Java it is usually uppercase for the first character of a class name.
>>in Java the standard is to use small letter for the first letter of variable and class
Only for variables
Only for variables
ASKER
I can loop through my record in JSP, however, I want to be able to check each record to identified the CustNum. I catigorized each CustNum as Gold(G), Silver(S). base on the first 6 difit of the Custnum I can detrmine whether this Cust is G or S.
I tried to do the following but faild:
int CardAcctNum=(linteger)e.ne xtElement( );
however, in my JSP I am able to display it as <%= e.nextElement()%>. what is the data type of the e.nextElement()? and how can I assign it variable and check the first 6 digit?
Thanks
I tried to do the following but faild:
int CardAcctNum=(linteger)e.ne
however, in my JSP I am able to display it as <%= e.nextElement()%>. what is the data type of the e.nextElement()? and how can I assign it variable and check the first 6 digit?
Thanks
Where is the Enumeration coming from - on what collection is it called and what's in it?
ASKER
CEHJ,
as you see that I am learning my way to do this. I find out that I have 2 type custmer, and each have the starting digit diffrent. I tried to do if statement in JSP to detrmine what type of customer. however, the type of custmer is exist in my database and I can pull it in. so I did add the field the vector.
rs = statement.executeQuery(Cus tNum);
while (rs.next())
{
CustNum=rs.getBigDecimal(" Custnum");
CType = rs.getString("Type")
ret.addElement(CustNum);
ret.addElement(CType);
}
this is working, but is this correct? when I do v.size() the size show 2 record. I look at it as 1 record diffrent field but Vector see it as 2 record.
when I retrieve it in JSP I do:
Vector v = new getNumber().getCustNumber( );
Enumeration e = v.elements();
while (e.hasMoreElements()) {
%>
<td>Cust Number:</td><td align=left><%= e.nextElement()%></td><td> Type: <%= e.nextElement()%></td>
<%
}
%>
the output is:
Cust Number: 1111111111111112222 Type G
Please let me know if I am doing this correctly.
Thanks
as you see that I am learning my way to do this. I find out that I have 2 type custmer, and each have the starting digit diffrent. I tried to do if statement in JSP to detrmine what type of customer. however, the type of custmer is exist in my database and I can pull it in. so I did add the field the vector.
rs = statement.executeQuery(Cus
while (rs.next())
{
CustNum=rs.getBigDecimal("
CType = rs.getString("Type")
ret.addElement(CustNum);
ret.addElement(CType);
}
this is working, but is this correct? when I do v.size() the size show 2 record. I look at it as 1 record diffrent field but Vector see it as 2 record.
when I retrieve it in JSP I do:
Vector v = new getNumber().getCustNumber(
Enumeration e = v.elements();
while (e.hasMoreElements()) {
%>
<td>Cust Number:</td><td align=left><%= e.nextElement()%></td><td>
<%
}
%>
the output is:
Cust Number: 1111111111111112222 Type G
Please let me know if I am doing this correctly.
Thanks
I would use an Iterator. You're right - it's two values in one row. You need
Vector row = new Vector(2);
row.addElement(CustNum);
row.addElement(CType);
ret.addElement(row);
Vector row = new Vector(2);
row.addElement(CustNum);
row.addElement(CType);
ret.addElement(row);
ASKER
and how retrieve it? would that change?
You retrieve it thus
Iterator i = ret.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
BigInteger custNum = (BigInteger)row.get(0);
String name = (String)row.get(1);
}
Iterator i = ret.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
BigInteger custNum = (BigInteger)row.get(0);
String name = (String)row.get(1);
}
You can also loop through:
for ( int i = 0, count = ret.size () ; i < count ; i ++ )
{
Vector row = ( Vector ) ret.get ( i ) ;
}
for ( int i = 0, count = ret.size () ; i < count ; i ++ )
{
Vector row = ( Vector ) ret.get ( i ) ;
}
ASKER
CEHJ
I tried to use this:
Vector v = new getNumber().getCustNumber( );
Iterator i = ret.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
BigInteger custNum = (BigInteger)row.get(0);
String name = (String)row.get(1);
}
but I am getting error:
Undefined variable or class name: ret
Iterator i = ret.iterator();
I tried to use this:
Vector v = new getNumber().getCustNumber(
Iterator i = ret.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
BigInteger custNum = (BigInteger)row.get(0);
String name = (String)row.get(1);
}
but I am getting error:
Undefined variable or class name: ret
Iterator i = ret.iterator();
ASKER
I change the code to be:
Vector v = new getNumber().getCustNumber( );
Iterator i = v.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
BigInteger CardAcctNum = (BigInteger)row.get(0);
String name = (String)row.get(1);
.......
I am getting the following error stack..
java.lang.ClassCastExcepti on
========================== ========== ==
Message:
========================== ========== ==
null
========================== ========== ==
Localized Message:
========================== ========== ==
null
========================== ========== ==
Stack Trace:
========================== ========== ==
java.lang.ClassCastExcepti on
at org.apache.jsp.eVisa$jsp._ jspService (eVisa$jsp .java:662)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.jasper.servlet. JspServlet $JspServle tWrapper.s ervice(Jsp Servlet.ja va:201)
at org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:381)
at org.apache.jasper.servlet. JspServlet .service(J spServlet. java:473)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:247 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 93)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:243)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:190)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.valves .Certifica tesValve.i nvoke(Cert ificatesVa lve.java:2 46)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardCon text.invok e(Standard Context.ja va:2347)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:180 )
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.valves .ErrorDisp atcherValv e.invoke(E rrorDispat cherValve. java:170)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:170 )
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.valves .AccessLog Valve.invo ke(AccessL ogValve.ja va:468)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :174)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.connec tor.http.H ttpProcess or.process (HttpProce ssor.java: 1027)
at org.apache.catalina.connec tor.http.H ttpProcess or.run(Htt pProcessor .java:1125 )
at java.lang.Thread.run(Threa d.java:534 )
Vector v = new getNumber().getCustNumber(
Iterator i = v.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
BigInteger CardAcctNum = (BigInteger)row.get(0);
String name = (String)row.get(1);
.......
I am getting the following error stack..
java.lang.ClassCastExcepti
==========================
Message:
==========================
null
==========================
Localized Message:
==========================
null
==========================
Stack Trace:
==========================
java.lang.ClassCastExcepti
at org.apache.jsp.eVisa$jsp._
at org.apache.jasper.runtime.
at javax.servlet.http.HttpSer
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.connec
at org.apache.catalina.connec
at java.lang.Thread.run(Threa
>>getNumber().getCustNumbe r()
I thought that returned BigInteger ..?
I thought that returned BigInteger ..?
if you are just displaying them then you may not even need to cast:
Vector v = new getNumber().getCustNumber( );
Iterator i = v.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
Object CardAcctNum = row.get(0);
Object name = row.get(1);
Vector v = new getNumber().getCustNumber(
Iterator i = v.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
Object CardAcctNum = row.get(0);
Object name = row.get(1);
>> Vector row = (Vector)i.next();
What does i.next () return? A Vector, or something else?
What does i.next () return? A Vector, or something else?
ASKER
Mayankeagle
it should retrun 2 values, here is the how they have been added to the vector:
row.addElement(AcctNum);
row.addElement(CType);
ret.addElement(row);
it should retrun 2 values, here is the how they have been added to the vector:
row.addElement(AcctNum);
row.addElement(CType);
ret.addElement(row);
ASKER
CHEJ,
the value retrun from the vector to JSP working just fine with the following:
if you are just displaying them then you may not even need to cast:
Vector v = new getNumber().getCustNumber( );
Iterator i = v.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
Object CardAcctNum = row.get(0);
Object name = row.get(1);
But I need to convert them to String and Integer so I can do the following:
1-display the number on my JSP like Credit card like Cust Number: ************44445
2-before displaying them I need to be able to send them include an XML string to be encrypted 3DES. I don't think I will be able to encrypt object.
Thanks
the value retrun from the vector to JSP working just fine with the following:
if you are just displaying them then you may not even need to cast:
Vector v = new getNumber().getCustNumber(
Iterator i = v.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
Object CardAcctNum = row.get(0);
Object name = row.get(1);
But I need to convert them to String and Integer so I can do the following:
1-display the number on my JSP like Credit card like Cust Number: ************44445
2-before displaying them I need to be able to send them include an XML string to be encrypted 3DES. I don't think I will be able to encrypt object.
Thanks
ASKER
I was able to convert the name to string but not the CustNum:
BigInteger CustNum = (BigInteger)row.get(0); <-- this is not working
String name = (String)row.get(1); <--- this is working fine
BigInteger CustNum = (BigInteger)row.get(0); <-- this is not working
String name = (String)row.get(1); <--- this is working fine
ASKER
in my class the vector use BigDecimal not bigInteger. but my problem now is that my vector retruns the first value stored in vector until the loop completed.
the following is print statment while I add to the vector:
while (rs.next())
{
CustNum=rs.getBigDecimal(" CustNum");
CType = rs.getString("TYPE");
row.addElement(CustNum);
row.addElement(CType);
ret.addElement(row);
System.out.println(CustNum );
}
***********1119
***********2220
***********3331
but in my JSP:
Vector v = new getNumber().getCustNumber( );
Iterator i = v.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
Object CustNum = row.get(0);
Object name = row.get(1);
system.out.println(CustNum );
}
that retrun the wrong result:
***********1119
***********1119
***********1119
the following is print statment while I add to the vector:
while (rs.next())
{
CustNum=rs.getBigDecimal("
CType = rs.getString("TYPE");
row.addElement(CustNum);
row.addElement(CType);
ret.addElement(row);
System.out.println(CustNum
}
***********1119
***********2220
***********3331
but in my JSP:
Vector v = new getNumber().getCustNumber(
Iterator i = v.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
Object CustNum = row.get(0);
Object name = row.get(1);
system.out.println(CustNum
}
that retrun the wrong result:
***********1119
***********1119
***********1119
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> But I need to convert them to String and Integer so I can do the following:
you can just use the toString() method, no need to cast to do that.
Vector v = new getNumber().getCustNumber( );
Iterator i = v.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
Object CardAcctNum = row.get(0);
Object name = row.get(1);
...
out.println("Card#: "+CardAcctNum);
you can just use the toString() method, no need to cast to do that.
Vector v = new getNumber().getCustNumber(
Iterator i = v.iterator();
while (i.hasNext()) {
Vector row = (Vector)i.next();
Object CardAcctNum = row.get(0);
Object name = row.get(1);
...
out.println("Card#: "+CardAcctNum);
ASKER
so you want me to do the following:
while (rs.next())
{
Vector row=new Vector(2);
CustNum=rs.getBigDecimal(" CustNum");
CType = rs.getString("TYPE");
row.addElement(CustNum);
row.addElement(CType);
ret.addElement(row);
System.out.println(CustNum );
}
while (rs.next())
{
Vector row=new Vector(2);
CustNum=rs.getBigDecimal("
CType = rs.getString("TYPE");
row.addElement(CustNum);
row.addElement(CType);
ret.addElement(row);
System.out.println(CustNum
}
ASKER
Vector ret=new Vector();
while (rs.next())
{
Vector row=new Vector(2);
CustNum=rs.getBigDecimal(" CustNum");
CType = rs.getString("TYPE");
row.addElement(CustNum);
row.addElement(CType);
ret.addElement(row);
System.out.println(CustNum );
}
while (rs.next())
{
Vector row=new Vector(2);
CustNum=rs.getBigDecimal("
CType = rs.getString("TYPE");
row.addElement(CustNum);
row.addElement(CType);
ret.addElement(row);
System.out.println(CustNum
}
That looks OK
you'd be better off using an ArrayList instead of a Vector, it'll give you better performance.
In fact an array would probably be more suitable as you know tyhe required size
List ret=new ArrayList();
while (rs.next())
{
Object[] row=new Object[2];
CustNum=rs.getBigDecimal(" CustNum");
CType = rs.getString("TYPE");
row[0] = CustNum;
row[1] CType;
ret.add(row);
System.out.println(CustNum );
}
In fact an array would probably be more suitable as you know tyhe required size
List ret=new ArrayList();
while (rs.next())
{
Object[] row=new Object[2];
CustNum=rs.getBigDecimal("
CType = rs.getString("TYPE");
row[0] = CustNum;
row[1] CType;
ret.add(row);
System.out.println(CustNum
}
then to read it:
List v = new getNumber().getCustNumber( );
Iterator i = v.iterator();
while (i.hasNext()) {
Object[] row = (Object[])i.next();
String CardAcctNum = row[0].toString();
String name = row[1].toString();
List v = new getNumber().getCustNumber(
Iterator i = v.iterator();
while (i.hasNext()) {
Object[] row = (Object[])i.next();
String CardAcctNum = row[0].toString();
String name = row[1].toString();
:-)
try:
return (int) CustNum;