20非常有用的Java程序片段(1)
2013-06-14 14:57 陈皓酷壳网 我要评论(0) 字号:T | T
下面是20个非常有用的Java程序片段,希望能对你有用。
AD:2013大数据全球技术峰会课程PPT下载
下面是20个非常有用的Java程序片段,希望能对你有用。
1. 字符串有整型的相互转换
String a = (2); //integer to numeric string
int i = (a); //numeric string to an int
2. 向文件末尾添加内容
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(”filename”, true));
(”aString”);
} catch (IOException e) {
// error processing code
} finally {
if (out != null) {
();
}
}
3. 得到当前方法的名字
String methodName = ().getStackTrace()[1].getMethodName();
4. 转字符串到日期
= ().parse(date String);
或者是:
SimpleDateFormat format = new SimpleDateFormat( "" );
Date date = ( myString );
5. 使用JDBC链接Oracle
public class OracleJdbcTest
{
String driverClass = "";
Connection con;
public void init(FileInputStream fs) throws ClassNotFoundException, SQLException, FileNotFoundException, IOException
{
Properties props = new Properties();
(fs);
String url = ("");
String userName = ("");
String password = ("");
(driverClass);
con=(url, userName, password);
}
public void fetch() throws SQLException, IOException
{
PreparedStatement ps = ("select SYSDATE from dual");
ResultSet rs = ();
while (())
{
// do the thing you do
}
();
();
}
public static void main(String[] args)
{
OracleJ
非常有用的java代码段 来自淘豆网m.daumloan.com转载请标明出处.