Checking against a Folder Tree.
I need some help. I'm currently calling to a SQL database, and reading those records. I need to be able to take the data from the groupId field and check to see if there has been a Folder created with that name. If so, move onto the next record. If not, then create that Folder with the name of the groupId. I just can't get it to work properly. I have the call to the SQL database correct, but can't seem to get a Folder check/create working. This is my current code:
Code:
package *;
import *.TestBean;
import java.io.File;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class Test_run2 {
private static Test_run2 instance;
/**
* @return a object.
*/
public static Test_run2 getInstance() {
if (instance == null) {
instance = new Test_run2();
}
return instance;
}
private Test_run2() {
super();
}
/**
* Retrieve a test beans
*
*/
public List<TestBean> getIDList() throws SQLException {
List<TestBean> testBeans = new ArrayList<TestBean>();
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:Username/Password@Database:PORT:DEV");
String sql = "select ID,GROUPID from TBL";
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rset = pstmt.executeQuery();
TestBean testBean = null;
String devId = null;
String groupId = null;
while (rset.next()) {
testBean = new TestBean();
devId = rset.getString(1);
groupId = rset.getString(2);
testBean.setDevId(devId);
testBean.setGroupId(groupId);
testBeans.add(testBean);
if (groupId.equals("NAME OF FOLDER")) {
System.out.println("GROUP ID EQUALS NAME OF FOLDER");
} else {
System.out.println("DOESN'T EQUAL FOLDER"+groupId);
}
}
rset.close();
pstmt.close();
conn.close();
return testBeans;
}
public static void main(String[] args) {
List<TestBean> beans;
try {
beans = Test_run.getInstance().getIDList();
int count = 0;
for (TestBean testBean:beans) {
count++;
}
System.out.println("count=<"+count+">");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Any help is appreciated! Thanks!