易截截图软件、单文件、免安装、纯绿色、仅160KB

20个非常有用的Java程序片段

1. 字符串有整型的相互转换
  Java代码
  String a = String.valueOf(2);   //integer to numeric string
  int i = Integer.parseInt(a); //numeric string to an int
  2. 向文件末尾添加内容
  Java代码
  BufferedWriter out = null;
  try {
  out = new BufferedWriter(new FileWriter(”filename”, true));
  out.write(”aString”);
  } catch (IOException e) {
  // error processing code
  } finally {
  if (out != null) {
  out.close();
  }
  }
  3. 得到当前方法的名字
  Java代码
  String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
  4. 转字符串到日期
  Java代码
  java.util.Date = java.text.DateFormat.getDateInstance().parse(date String);
  或者是:
  SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" );
  Date date = format.parse( myString );
  5. 使用JDBC链接Oracle
  Java代码
  public class OracleJdbcTest
  {
  String driverClass = "oracle.jdbc.driver.OracleDriver";
  Connection con;
  public void init(FileInputStream fs) throws ClassNotFoundException, SQLException, FileNotFoundException, IOException
  {
  Properties props = new Properties();
  props.load(fs);
  String url = props.getProperty("db.url");
  String userName = props.getProperty("db.user");
  String password = props.getProperty("db.password");
  Class.forName(driverClass);
  con=DriverManager.getConnection(url, userName, password);
  }
  public void fetch() throws SQLException, IOException
  {
  PreparedStatement ps = con.prepareStatement("select SYSDATE from dual");
  ResultSet rs = ps.executeQuery();
  while (rs.next())
  {
  // do the thing you do
  }
  rs.close();
  ps.close();
  }
  public static void main(String[] args)
  {
  OracleJdbcTest test = new OracleJdbcTest();
  test.init();
  test.fetch();
  }
  }
6. 把 Java util.Date 转成 sql.Date
  Java代码
  java.util.Da


相关文档:

java xml

First
Parsing an XML Document
To read an XML document, you need a DocumentBuilder object, which you get from a DocumentBuilderFactory, like this:DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
You can now read a docu ......

rxtx取代javax.comm实现Java跨平台设备端口通信

from Rxtx
This page is for general content regarding the use of rxtx. Feel free to add your own content.
Using RXTX In Eclipse
Deploying JAVA with RXTX
I wrote an app several months ago using javax.comm on windows. Sun has left me high and dry. rxtx help!
download ftp://ftp.qbang.org/pub/rx ......

java学习资料站

1、 http://java.sun.com/ ;;(英文)
Sun的Java网站,是一个应该经常去看的地方。不用多说。
2、 http://www-900.ibm.com/developerWorks/cn/ ;;
IBM的developerWorks网站,英语好的直接去英文主站点看。这里不但是一个极好的面向对象的分析设计网站,也是Web Services,Java,Linux极好的网站。强烈推荐!!!
3、 h ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号