Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - In JSP, how to convert the value of String into int and insert it into the database?
In JSP, how to convert the value of String into int and insert it into the database?
1 how to convert String into integer int?

A. there are two methods:

1).int I = integer . parse int([String]); or

i = Integer.parseInt([String],[int radix]);

2).int i = Integer.valueOf(my_str)。 int value();

Note: the method of converting strings into double, float and long is similar.

2 how to convert integer int into string?

A. there are three ways:

1.)String s = String . value of(I);

2.)String s = integer . tostring(I);

3.) String s = ""+i;

Note: Double, float and long are converted to strings in a similar way.

Java data type conversion ynniebo[ collection]

Keyword type conversion

source

This is an example of data conversion in JAVA. For everyone to learn.

Package cn.com.lwkj.erts.register;

Import java.sql.date;

Public class type change {

public TypeChange() {

}

//Change the string type to int type

Public static int String point(String intstr)

{

Integer;;

integer = integer . value of(intstr);

Returns integer. intvalue ();

}

//change int type to string type.

Public static string intToString(int value)

{

Integer integer = new integer (value);

Returns integer. tostring ();

}

//Change the string type to floating-point type

Common static floating-point stringToFloat(String floatstr)

{

Float float;

float ee = float . value of(float str);

Returns floatee. floatvalue ();

}

//Change floating-point type to string type

Public static string floatToString (floating point value)

{

FloatFloat = new float (value);

Returns floatee.tostring ();

}

//Change the string type to sqlDate type.

Public static java.sql.datestringtote (string datestr)

{

Returns java.sql.date.valueof (datestr);

}

//change sqlDate type to string type.

Public static string datetostring (java.sql.datedatee)

{

return datee . tostring();

}

Public static void main(String[] args)

{

Java.sql.Date day;

day = type change . string tote(" 2003- 1 1-3 ");

Stringstrday = typechange.datetostring (day);

system . out . println(strday);

}

}

Common data type conversion functions in JAVA

Although it can be found in JAVA API, tidy it up and make a backup.

String-> byte

Byte static byte analysis byte (string s)

Bytes-> line

Byte static string to string (byte b)

char-& gt; line

Character static string to string (char c)

String-> short

Short static short parseShort (string s)

Short->; line

Short static string toString (short s)

String-> integer

Integer static int parseInt (string s)

Integer-> line

Integer static string tostring(int i)

String-> long

Long static long parseLong (string s)

long->; line

Long static string toString(Long i)

String-> float

Floating-point static floating-point parseFloat (string s)

Floating-> line

Converts a static string to a string (floating point f)

String-> double;twofold

Double static double parseDouble (string s)

double-& gt; line

Double static string toString (double d)