日期:2014-05-16  浏览次数:20421 次

键盘输入目录,将子目录和最后修改时间存入数据库

思路:

1,获取键盘中输入的值

2,根据输入的值,遍历出所有的子目录,将子目录封装成对象,并放入集合中

3. 从集合中取出对象,并存入到数据库

4,测试结果

?

/**

?*创建文件对象

?*@author Li Jia Xuan

?*@version 1.0

?*@since 2012-10-29

?*@time 下午03:32:34

?*/

public class File1 {

? private int i=5;

? private String path;

? private String last_time;

?File1(int i, String path, String last_time) {

//uper();

this.i = i;

this.path = path;

this.last_time = last_time;

}

public int getI() {

return i;

}

public String getPath() {

return path;

}

public String getLast_time() {

return last_time;

}?

?

}

//------------------------------------------------

/**
?*创建存入数据库的方法
?*@author Li Jia Xuan
?*@version 1.0
?*@since 2012-10-29
?*@time 下午04:45:52
?*/
public class TestConn {
private static final String DRIVER_NAMR="oracle.jdbc.driver.OracleDriver";?
private static final String URL="jdbc:oracle:thin:@192.168.1.254:1521:orcl";?
private static final String USER="lijiaxuan";?
private static final String PWD="123456";
public static void test(File1 f) {

Connection conn =null;
PreparedStatement ps=null;
try {
Class.forName(DRIVER_NAMR);
conn = DriverManager.getConnection(URL, USER, PWD);
ps = conn.prepareStatement("insert into file1 values(seq_file.nextval,?,?)");
//ps.setInt(1, f.getI());
ps.setString(1, f.getPath());
ps.setString(2, f.getLast_time());
int i = ps.executeUpdate();
if (i > 0) {
System.out.println("插入成功");
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(ps!=null){
try {
ps.close();
} catch (SQLException e