leo_wh_cheung
asked on
ASP command change to Java Command
I am translating a ASP Program to Java Program
What Java commands that I need to use to replace the following ASP commands:
isnumeric()
isDate()
formatNumber()
left()
right()
ASC()
HexChar()
Chr()
Also, How can I find out the java commands about retrieving the field name and defined size of the field from a recordset by using field index in Java Command?
In ASP, field name can be obtained from :
rstemp.fields(i).name
In ASP, defined size of the field can be obtained from :
rstemp.fields(i).definedsi ze
What Java commands that I need to use to replace the following ASP commands:
isnumeric()
isDate()
formatNumber()
left()
right()
ASC()
HexChar()
Chr()
Also, How can I find out the java commands about retrieving the field name and defined size of the field from a recordset by using field index in Java Command?
In ASP, field name can be obtained from :
rstemp.fields(i).name
In ASP, defined size of the field can be obtained from :
rstemp.fields(i).definedsi
isnumeric()
isDate()
-----------
For these, you'll hafta do as suggested above...write a quick method or code block that'll try converting and return false if an exception is thrown.
formatNumber()
--------------
I'm not sure what this guy is supposed to do.
left()
right()
-------
For these two, just use substring(). Or write something similar to the following:
public static String left(String s, int spaces) {
return s.substring(0, spaces);
}
public static String right(String s, int spaces) {
return s.substring(s.length()-spa ces, s.length());
}
ASC()
Chr()
-----
The ASCII character set still uses 0-255, so you're free to convert between chars and ints if you like. Uhh...I forget which returns what, so maybe I'll have this backwards.
public static char Chr(int asc) {
return (char)asc;
}
public static String sChr(int asc) {
return String.valueOf((char)asc);
}
public static int Asc(char chr) {
return (int)chr;
}
public static int Asc(String chr) {
return Integer.valueOf(chr).intVa lue();
}
HexChar()
---------
I'm not sure what this guy does either, but Java converts between decimal and hex notation pretty easily.
The following data access examples use a JDBC ResultSet interface (the ADO equivalent of a RecordSet). The info you're looking for comes from the ResultSetMetaData interface. (rs.getMetaData())
rstemp.fields(i).name
---------------------
rstemp.getMetaData().getCo lumnName() ;
rstemp.fields(i).definedsi ze
-------------------------- --
rstemp.getMetaData().getCo lumnDispla ySize();
For more info on all of this stuff, view the Java API at http://java.sun.com/j2se/1.3/docs/api/index.html
Your String related info will be under the 'java.lang' package. Your JDBC info will be under 'java.sql'.
Hope this helps!
Marius
isDate()
-----------
For these, you'll hafta do as suggested above...write a quick method or code block that'll try converting and return false if an exception is thrown.
formatNumber()
--------------
I'm not sure what this guy is supposed to do.
left()
right()
-------
For these two, just use substring(). Or write something similar to the following:
public static String left(String s, int spaces) {
return s.substring(0, spaces);
}
public static String right(String s, int spaces) {
return s.substring(s.length()-spa
}
ASC()
Chr()
-----
The ASCII character set still uses 0-255, so you're free to convert between chars and ints if you like. Uhh...I forget which returns what, so maybe I'll have this backwards.
public static char Chr(int asc) {
return (char)asc;
}
public static String sChr(int asc) {
return String.valueOf((char)asc);
}
public static int Asc(char chr) {
return (int)chr;
}
public static int Asc(String chr) {
return Integer.valueOf(chr).intVa
}
HexChar()
---------
I'm not sure what this guy does either, but Java converts between decimal and hex notation pretty easily.
The following data access examples use a JDBC ResultSet interface (the ADO equivalent of a RecordSet). The info you're looking for comes from the ResultSetMetaData interface. (rs.getMetaData())
rstemp.fields(i).name
---------------------
rstemp.getMetaData().getCo
rstemp.fields(i).definedsi
--------------------------
rstemp.getMetaData().getCo
For more info on all of this stuff, view the Java API at http://java.sun.com/j2se/1.3/docs/api/index.html
Your String related info will be under the 'java.lang' package. Your JDBC info will be under 'java.sql'.
Hope this helps!
Marius
oops, my bad...it shoulda been:
rstemp.fields(i).name
---------------------
rstemp.getMetaData().getCo lumnName(i );
rstemp.fields(i).definedsi ze
-------------------------- --
rstemp.getMetaData().getCo lumnDispla ySize(i);
I forgot to supply the column index parameter.
Marius
rstemp.fields(i).name
---------------------
rstemp.getMetaData().getCo
rstemp.fields(i).definedsi
--------------------------
rstemp.getMetaData().getCo
I forgot to supply the column index parameter.
Marius
String formatNumber(double value)
{
return NumberFormat.getInstance() .format(ne w java.math.BigDecimal(value ).setScale (2,0))
}
//setScale is depends on ur program
String trim(String s)
{
return s.trim();
}
boolean isDate(String s)
{
try
{
new java.util.Date(s);
return true;
}
catch(Exception e)
{
return false;
}
}
int Asc(char c)
{
return (int)c;
}
char Chr(int c)
{
return (char)c;
}
boolean isNumeric(String s)
{
try
{
Double.parseDouble(s);
return true;
}
catch(Exception e)
{
return false;
}
}
{
return NumberFormat.getInstance()
}
//setScale is depends on ur program
String trim(String s)
{
return s.trim();
}
boolean isDate(String s)
{
try
{
new java.util.Date(s);
return true;
}
catch(Exception e)
{
return false;
}
}
int Asc(char c)
{
return (int)c;
}
char Chr(int c)
{
return (char)c;
}
boolean isNumeric(String s)
{
try
{
Double.parseDouble(s);
return true;
}
catch(Exception e)
{
return false;
}
}
boolean isNumeric(String s)
{
try
{
Double.valueOf(s).doubleVa lue();
return true;
}
catch(Exception e)
{
return false;
}
}
{
try
{
Double.valueOf(s).doubleVa
return true;
}
catch(Exception e)
{
return false;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
{
try
{
new java.util.Date(s);
return true;
}
catch(Exception e)
{
return false;
}
}
int Asc(char c)
{
return (int)c;
}
boolean isNumeric(String s)
{
try
{
Double.parseDouble(s);
return true;
}
catch(Exception e)
{
return false;
}
}