Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Monday, January 12, 2009

convert integer to string

public class ConvertIntToString {
public static void main(String[] args) {

int aInt = 1;

String aString = Integer.toString(aInt);

}
}

Monday, November 24, 2008

Convert HexString to Big Integer

String reverse ="D7821A727982782A";
String sAuthoCode ="";

BigInteger bi_try = new BigInteger(reverse, 16);
BigInteger bi_autho = new BigInteger(sAuthoCode, 16);
BigInteger bi_pref = new BigInteger("AB7",16);

BigInteger bi_result;
bi_result= bi_pref.add(bi_try).add(bi_autho).subtract(bi_subf);

Friday, November 21, 2008

DropDownList from DB to JSP

/////form.jsp

<bean:define id="listCompanyType" name="RegForm" property="LISTCOMPANYTYPE"/>
<html:select property="companyType">
<html:options collection="listCompanyType" property="value" labelProperty="label"/>
</html:select>


//// or use this method

<html:select property="companyType">
<html:optionsCollection property="LISTCOMPANYTYPE" label="label" value="value"/>
</html:select>


/// beanForm.java

public List getLISTCOMPANYTYPE(){
RegManager oRegManager = new RegManager();
try {
PropertyFileReader oSQLReader = new PropertyFileReader("properties.registration.reg-sql");
String sCompanySQL = oSQLReader.getKey("companytype.sql.query.getlist");

LISTCOMPANYTYPE = oRegManager.getDropList(sCompanySQL);
} catch (Exception ex) {
ex.printStackTrace();
}
return LISTCOMPANYTYPE;
}

Thursday, November 20, 2008

JDBCConnection

/** getJDBCConnection
* @return Connection
**/
public Connection getJDBCConnection() throws Exception{

Connection connection= null;

String driver = dbDriver;
String user = dbId;
String password = dbPasswd;
String url = dbUrl;

Class.forName(driver);
connection = DriverManager.getConnection(url, user, password);

return connection;
}

/////////////////////
#properties file setting
global.database.dbUrl=jdbc:mysql://localhost:3306/aseanreg
global.database.dbId=root
global.database.dbPasswd=password
global.database.dbDriver=com.mysql.jdbc.Driver

Thursday, November 13, 2008

Java Char to String

2 ways...

if c is the character...

1. Use String.valueOf(c), This gives a String representation of the argument i.e. c

2. Add to StringBuffer and finally get a String by calling toString() on the StringBuffer

Friday, October 24, 2008

convert date to string

import java.text.SimpleDateFormat;


SimpleDateFormat oDateFormat = new SimpleDateFormat("ddMMyyyy");
sDateRequest = oDateFormat.format(d_dateRequest);
sDatePublish = oDateFormat.format(d_datePublish);

Thursday, August 07, 2008

Print Error Message (exception)

Print Error Message

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);3
ex.printStackTrace(pw);
pw.close();
System.out.println(sw.toString());