Solved

ASP command change to  Java Command

Posted on 2001-06-06
6
272 Views
Last Modified: 2010-03-31
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).definedsize

0
Comment
Question by:leo_wh_cheung
  • 4
  • 2
6 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 6159481
boolean isNumeric(String s)
{
     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;
     }
}
0
 
LVL 2

Expert Comment

by:xxMariusxx
ID: 6161354
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()-spaces, 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).intValue();
}

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().getColumnName();

rstemp.fields(i).definedsize
----------------------------
rstemp.getMetaData().getColumnDisplaySize();

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
0
 
LVL 2

Expert Comment

by:xxMariusxx
ID: 6161551
oops, my bad...it shoulda been:

rstemp.fields(i).name
---------------------
rstemp.getMetaData().getColumnName(i);

rstemp.fields(i).definedsize
----------------------------
rstemp.getMetaData().getColumnDisplaySize(i);

I forgot to supply the column index parameter.

Marius
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 6162542
String formatNumber(double value)
{

return NumberFormat.getInstance().format(new 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;
    }
}
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 6162556
boolean isNumeric(String s)
{
   try
   {
        Double.valueOf(s).doubleValue();
        return true;
   }
   catch(Exception e)
   {
        return false;
   }
}
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 50 total points
ID: 6162562
s.substring(0,pos)->left
s.substring(s.length()-pos,s.length())->right
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java jdbc batch example 8 35
expectj telnet failing 5 37
eclipse buid path vs tomcat lib path 10 24
Desingning Refactoring existing code 2 24
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question