package docman; import java.sql.*; import java.util.ArrayList; import java.io.FileOutputStream; import java.io.File; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Cookie; public class DBBean { public static final String DATA_PATH = "C:\\123Data\\JavaProjects\\docman\\Data\\"; public String getDataPath() { return DATA_PATH; } // database connection private Connection connection=null; // JDBC URL, change the string value below // appropriately String dbUrl = "jdbc:odbc:docman"; // user name for database access String dbUserName = ""; // password for database access String dbPassword = ""; // JDBC driver name, the value depends // on the driver you are using String JDBCDriverName = "sun.jdbc.odbc.JdbcOdbcDriver"; public void setUrl(String dbUrl) { // this method allows the JDBC URL to be changed // if the different one from the default // is needed this.dbUrl = dbUrl; } public void setDbUserName(String dbUserName) { // this method allows the database // user name to be changed this.dbUserName = dbUserName; } public void setDbPassword(String dbPassword) { // this method allows the database // password to be changed this.dbPassword = dbPassword; } public void setJDBCDriverName (String JDBCDriverName) { // this method allows the database // JDBC driver to be changed this.JDBCDriverName = JDBCDriverName; } public void connect() { // try to connect to the database // using url, username, and password // previously set connect(dbUrl, dbUserName, dbPassword); } public void connect (String url, String userName, String password) { // try to connect to the database // using url, username, and password // passed as parameters try { Class.forName( JDBCDriverName); connection = DriverManager.getConnection(url, userName, password); } catch (Exception e) {} } public ArrayList getChildObjects(String id, String userName, String password) { //the return value; ArrayList records = new ArrayList(); try { if (connection==null) connect(); String sql = "SELECT ID, Type, Name" + " FROM Objects" + " WHERE ParentID=" + " (SELECT ObjectID FROM Permissions" + " WHERE ObjectID=" + id + " AND UserID=" + " (SELECT ID FROM Users" + " WHERE UserName='" + userName + "'" + " AND Password='" + password + "'))" + " ORDER BY Type ASC"; Statement s = connection.createStatement(); ResultSet r = s.executeQuery( sql ); while(r.next()) { records.add(r.getString("ID") + "," + r.getString("Type") + "," + r.getString("Name")); } s.close(); // Also closes ResultSet } catch(Exception e) { e.printStackTrace(); } return records; } public String getCookie( HttpServletRequest request, String cookie) { // returns the cookie value if the cookie // is found in request, otherwise returns null Cookie cookies[] = request.getCookies(); if (cookies!=null) for (int i=0; i