Ejemplo n.º 1
0
    public MetadataBlob[] select(String selectString) {
      PreparedStatement stmt = null;
      try {
        stmt =
            conn.prepareStatement(
                "select writingKey, mapkey, blobdata from metadatablobs " + selectString + ";");
        ResultSet rs = stmt.executeQuery();
        List<MetadataBlob> list = new ArrayList<MetadataBlob>();
        while (rs.next()) {
          MetadataBlob f =
              new MetadataBlob(
                  rs.getString("writingkey"), rs.getString("mapkey"), rs.getString("blobdata"));
          list.add(f);
        }

        return list.toArray(new MetadataBlob[0]);
      } catch (SQLException sqe) {
        System.err.println("Error selecting: " + selectString);
        sqe.printStackTrace();
        return null;
      } finally {
        if (stmt != null)
          try {
            stmt.close();
          } catch (SQLException sqe2) {
            sqe2.printStackTrace();
          }
      }
    }
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");

    PrintWriter out = response.getWriter();
    Connection conn = null;
    PreparedStatement pstmt = null;
    try {
      System.out.println("Enrollno: 130050131049");
      // STEP 2: Register JDBC driver
      Class.forName(JDBC_DRIVER);

      // STEP 3: Open a connection
      System.out.println("Connecting to a selected database...");
      conn = DriverManager.getConnection(DB_URL, USER, PASS);
      System.out.println("Connected database successfully...");

      // STEP 2: Executing query
      String sql = "SELECT * FROM logindetails WHERE name = ?";
      pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, "Krut");

      ResultSet rs = pstmt.executeQuery();
      out.print("| <b>Name</b>| ");
      out.print("<b>Password</b>| ");
      out.println("</br>\n-------------------------------</br>");
      while (rs.next()) {
        out.println();
        out.print("| " + rs.getString(1));
        out.print("| " + rs.getString(2) + "|");
        out.println("</br>");
      }

    } catch (SQLException se) {
      // Handle errors for JDBC
      se.printStackTrace();
    } catch (Exception e) {
      // Handle errors for Class.forName
      e.printStackTrace();
    } finally {
      // finally block used to close resources
      try {
        if (pstmt != null) conn.close();
      } catch (SQLException se) {
      } // do nothing
      try {
        if (conn != null) conn.close();
      } catch (SQLException se) {
        se.printStackTrace();
      } // end finally try
    } // end try
  }
Ejemplo n.º 3
0
  public void display(ResultSet rs) {
    try {
      boolean recordNumber = rs.next();
      if (recordNumber) {
        payNo = rs.getString(1);
        pasNo = rs.getString(2);
        pasName = rs.getString(3);
        mode = rs.getString(4);
        dt = rs.getString(5);
        amount = rs.getString(6);
        rev = rs.getString(7);

        text1.setText(payNo);
        combo1.setSelectedItem(pasNo);
        combo2.setSelectedItem(pasName);
        combo4.setSelectedItem(mode);
        p_date.setText(dt);
        combo8.setSelectedItem(amount);
        combo3.setSelectedItem(rev);

      } else {
        JOptionPane.showMessageDialog(
            null, "Record Not found", "ERROR", JOptionPane.DEFAULT_OPTION);
      }
    } catch (SQLException sqlex) {
      sqlex.printStackTrace();
    }
  }
Ejemplo n.º 4
0
 public void deleteOption(String modelName, String optionSetName, String option) {
   try {
     int autoid = 0;
     String sql = "select id from automobile where name ='" + modelName + "';";
     ResultSet rs;
     rs = statement.executeQuery(sql);
     while (rs.next()) {
       autoid = rs.getInt("id"); // get auto_id
     }
     int opsid = 0;
     sql =
         "select id from optionset where name ='"
             + optionSetName
             + "' and auto_id= "
             + autoid
             + ";";
     rs = statement.executeQuery(sql);
     while (rs.next()) {
       opsid = rs.getInt("id"); // get option_id
     }
     sql = "delete from options where name= '" + option + "' and option_id= " + opsid;
     statement.executeUpdate(sql); // delete it using name and option_id
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 5
0
  public void updateOptionPrice(
      String modelName, String optionSetName, String optionName, float newPrice) {
    try {
      int autoid = 0;
      String sql = "select id from automobile where name ='" + modelName + "';";
      ResultSet rs = statement.executeQuery(sql);
      while (rs.next()) {
        autoid = rs.getInt("id"); // get auto_id
      }
      int opsid = 0;
      sql =
          "select id from optionset where name ='"
              + optionSetName
              + "' and auto_id= "
              + autoid
              + ";";
      rs = statement.executeQuery(sql);
      while (rs.next()) {
        opsid = rs.getInt("id"); // get option_id
      }
      sql =
          "update options set price = "
              + newPrice
              + " where name= '"
              + optionName
              + "' and option_id= "
              + opsid
              + ";";
      statement.executeUpdate(sql); // update it with name and option_id

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 6
0
  public void conectarBDdinamic(String ip) {

    if (ip == null) {
      ip = "192.168.8.231";
    }
    url = "jdbc:postgresql://" + ip + "/ventasalm";
    // javax.swing.JOptionPane.showMessageDialog(null, url);
    String estado;
    try {

      final String CONTROLADOR = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
      Class.forName(CONTROLADOR);
      // System.getProperty( "user.dir" )+"/CarpetaBD/NombredelaBasedeDatos.mdb";
      conexion = DriverManager.getConnection(url, user, pass);
      sentencia = conexion.createStatement();
      // estado="Conectado Correctamente";
    } catch (ClassNotFoundException ex1) {
      ex1.printStackTrace();
      javax.swing.JOptionPane.showMessageDialog(null, "Error Carga Driver");
      estado = "Servidor no esta disponible";
      // System.exit(1);
    } catch (SQLException ex) {
      ex.printStackTrace();
      javax.swing.JOptionPane.showMessageDialog(null, "Error Creacion Statement");
      estado = "Servidor no esta disponible";
      // System.exit(1);
    }
    // return estado;
  }
  /** Returns true if this VM has acquired the right to run this TestTask */
  private static DUnitRun getDUnitRun() {
    if (dunitRun != null) {
      System.out.println("BBB dunitRun not null returning");
      return dunitRun;
    }

    try {
      SwarmBB.getBB().getSharedLock().lock();
      Integer runId = (Integer) SwarmBB.getBB().getSharedMap().get(SwarmBB.RUN_ID);
      System.out.println("BBB runID=" + runId);
      if (runId != null) {
        dunitRun = Swarm.getDUnitRun(runId);
        System.out.println("BBB lookedUp RUN:" + dunitRun);
      } else {
        dunitRun = Swarm.generateNewDUnitRun();
        System.out.println(
            "BBB GENNED UP A RUN:" + dunitRun + " mapping to id:" + dunitRun.getId());
        SwarmBB.getBB().getSharedMap().put(SwarmBB.RUN_ID, dunitRun.getId());
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      SwarmBB.getBB().getSharedLock().unlock();
    }
    return dunitRun;
  }
  // execute and get results
  private void execute(Connection conn, String text, Writer writer, boolean commaSeparator)
      throws SQLException {

    BufferedWriter buffer = new BufferedWriter(writer);
    Statement stmt = conn.createStatement();
    stmt.execute(text);
    ResultSet rs = stmt.getResultSet();
    ResultSetMetaData metadata = rs.getMetaData();
    int nbCols = metadata.getColumnCount();
    String[] labels = new String[nbCols];
    int[] colwidths = new int[nbCols];
    int[] colpos = new int[nbCols];
    int linewidth = 1;

    // read each occurrence
    try {
      while (rs.next()) {
        for (int i = 0; i < nbCols; i++) {
          Object value = rs.getObject(i + 1);
          if (value != null) {
            buffer.write(value.toString());
            if (commaSeparator) buffer.write(",");
          }
        }
      }
      buffer.flush();
      rs.close();
    } catch (IOException ex) {
      if (Debug.isDebug()) ex.printStackTrace();
      // ok, exit from the loop
    } catch (SQLException ex) {
      if (Debug.isDebug()) ex.printStackTrace();
    }
  }
Ejemplo n.º 9
0
  public ExptLocatorTree(Genome g) {
    super();
    try {
      java.sql.Connection c = DatabaseFactory.getConnection(ExptLocator.dbRole);
      int species = g.getSpeciesDBID();
      int genome = g.getDBID();

      Statement s = c.createStatement();
      ResultSet rs = null;

      rs =
          s.executeQuery(
              "select e.name, e.version from experiment e, exptToGenome eg where e.active=1 and "
                  + "e.id=eg.experiment and eg.genome="
                  + genome);
      while (rs.next()) {
        String name = rs.getString(1);
        String version = rs.getString(2);
        ChipChipLocator loc = new ChipChipLocator(g, name, version);
        this.addElement(loc.getTreeAddr(), loc);
      }
      rs.close();

      rs =
          s.executeQuery(
              "select ra.name, ra.version from rosettaanalysis ra, rosettaToGenome rg where "
                  + "ra.id = rg.analysis and ra.active=1 and rg.genome="
                  + genome);
      while (rs.next()) {
        String name = rs.getString(1);
        String version = rs.getString(2);
        MSPLocator msp = new MSPLocator(g, name, version);
        this.addElement(msp.getTreeAddr(), msp);
      }
      rs.close();

      rs =
          s.executeQuery(
              "select ra.name, ra.version from bayesanalysis ra, bayesToGenome rg where "
                  + "ra.id = rg.analysis and ra.active=1 and rg.genome="
                  + genome);
      while (rs.next()) {
        String name2 = rs.getString(1);
        String version2 = rs.getString(2);
        ExptLocator loc2 = new BayesLocator(g, name2, version2);
        addElement(loc2.getTreeAddr(), loc2);
      }
      rs.close();
      s.close();

      DatabaseFactory.freeConnection(c);
    } catch (SQLException se) {
      se.printStackTrace(System.err);
      throw new RuntimeException(se);
    } catch (UnknownRoleException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 10
0
 public void close() {
   try {
     ps.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   ps = null;
   cxn = null;
 }
Ejemplo n.º 11
0
  /*
   * delete methods. select fisrt and then delete.
   */
  public void deleteAuto(String modelName) {

    try {
      String sql = "delete from automobile where name= '" + modelName + "';";
      statement.executeUpdate(sql); // delete direcly as it can be accessed in automobile
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 12
0
 public boolean delete(String table, String deleteString) {
   Statement stmt = null;
   try {
     stmt = conn.createStatement();
     stmt.executeUpdate("delete from " + table + " where " + deleteString + ";");
     return true;
   } catch (SQLException sqe) {
     sqe.printStackTrace();
     return false;
   } finally {
     if (stmt != null)
       try {
         stmt.close();
       } catch (SQLException sqe2) {
         sqe2.printStackTrace();
       }
   }
 }
 private static void doUpdate(String cmd) {
   try {
     Statement stmt = conn.createStatement();
     int howmany = stmt.executeUpdate(cmd);
     System.out.println(howmany + " records processed");
   } catch (SQLException e) {
     System.out.println("SQL Exception: " + e.getMessage());
     e.printStackTrace();
   }
 }
Ejemplo n.º 14
0
 public boolean delete() {
   Statement stmt = null;
   try {
     stmt = conn.createStatement();
     stmt.executeUpdate(deleteStatement());
     return true;
   } catch (SQLException sqe) {
     System.err.println(deleteStatement());
     sqe.printStackTrace();
     return false;
   } finally {
     if (stmt != null)
       try {
         stmt.close();
       } catch (SQLException sqe2) {
         sqe2.printStackTrace();
       }
   }
 }
 public void recordFail(String className, String methodName, long tookMs) {
   try {
     DUnitRun du = getDUnitRun();
     DUnitClassInfo duci = Swarm.getOrCreateDUnitClassInfo(className);
     DUnitMethodInfo dumi = Swarm.getOrCreateDUnitMethodInfo(methodName, duci.getId());
     Swarm.recordFailure(du, dumi, lastThrowable, tookMs);
   } catch (SQLException se) {
     se.printStackTrace();
   }
 }
Ejemplo n.º 16
0
  /*
   * update method. select the objects and then update.
   */
  public void updateAutoName(String oldName, String newName) {

    try {
      String sql = "update automobile set name = '" + newName + "'where name= '" + oldName + "';";
      statement.executeUpdate(
          sql); // update directly as it can be accessed directly from automobile table
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 17
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub
    // TODO Auto-generated method stub
    HttpSession session = request.getSession();
    request.setCharacterEncoding("UTF-8");

    BufferedInputStream fileIn = new BufferedInputStream(request.getInputStream());
    String fn = request.getParameter("fileName");
    byte[] buf = new byte[1024];
    File file = new File("/var/www/uploadres/" + session.getAttribute("username") + fn);
    BufferedOutputStream fileOut = new BufferedOutputStream(new FileOutputStream(file));
    while (true) {
      int bytesIn = fileIn.read(buf, 0, 1024);
      if (bytesIn == -1) break;
      else fileOut.write(buf, 0, bytesIn);
    }

    fileOut.flush();
    fileOut.close();
    System.out.println(file.getAbsolutePath());

    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      try {
        Connection conn = DriverManager.getConnection(url, user, pwd);
        Statement stmt = conn.createStatement();
        String sql =
            "UPDATE Users SET photo = '"
                + file.getName()
                + "' WHERE username='******'";
        stmt.execute(sql);
        //				PreparedStatement pstmt = conn.prepareStatement("UPDATE Users SET photo = ? WHERE
        // username='******'");
        //				InputStream inp = new BufferedInputStream(new FileInputStream(file));
        //				pstmt.setBinaryStream(1, inp, (int)file.length());
        //				pstmt.executeUpdate();
        System.out.println("OK");
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    } catch (InstantiationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Ejemplo n.º 18
0
 /*
  * build methods, initialization of the database
  */
 public void buildConnect() {
   try {
     Class.forName(jdbcDriver);
     connection = DriverManager.getConnection(dbUrl, user, passwd);
     statement = connection.createStatement();
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 19
0
 public boolean insert() {
   PreparedStatement stmt = null;
   try {
     stmt = conn.prepareStatement(insertStatement());
     stmt.setString(1, this.name);
     stmt.setString(2, this.b64string);
     stmt.executeUpdate();
     return true;
   } catch (SQLException sqe) {
     sqe.printStackTrace();
     return false;
   } finally {
     if (stmt != null)
       try {
         stmt.close();
       } catch (SQLException sqe2) {
         sqe2.printStackTrace();
       }
   }
 }
Ejemplo n.º 20
0
    public boolean delete() {
      PreparedStatement stmt = null;
      try {
        stmt = conn.prepareStatement("DELETE from metadatablobs where writingkey=? AND mapkey=?");

        stmt.setString(1, this.b64WritingKey);
        stmt.setString(2, this.b64mapkey);
        stmt.executeUpdate();
        return true;
      } catch (SQLException sqe) {
        sqe.printStackTrace();
        return false;
      } finally {
        if (stmt != null)
          try {
            stmt.close();
          } catch (SQLException sqe2) {
            sqe2.printStackTrace();
          }
      }
    }
Ejemplo n.º 21
0
    public boolean insert() {
      PreparedStatement stmt = null;
      try {
        stmt =
            conn.prepareStatement(
                "INSERT OR REPLACE INTO staticdata (name, staticdata) VALUES(?, ?)");

        stmt.setString(1, this.name);
        stmt.setString(2, this.b64string);
        stmt.executeUpdate();
        return true;
      } catch (SQLException sqe) {
        sqe.printStackTrace();
        return false;
      } finally {
        if (stmt != null)
          try {
            stmt.close();
          } catch (SQLException sqe2) {
            sqe2.printStackTrace();
          }
      }
    }
Ejemplo n.º 22
0
  /*
   * addAuto method. parse the Automobile object and add them to three tables.
   */
  public void addAuto(Automobile auto) {
    String name = null;
    float price = 0;
    int autoid = 0;
    String sql = null;
    try {
      String autoName = auto.getMake() + " " + auto.getModel();
      price = auto.getBasePrice();
      sql =
          "insert into automobile (name, base_price) values('"
              + autoName
              + "',"
              + price
              + ")"; // MySQL command
      statement.executeUpdate(sql); // add to automobile table

      sql = "select id from automobile where name ='" + autoName + "';";
      ResultSet rs = statement.executeQuery(sql); // use ResultSet object to receive
      while (rs.next()) {
        autoid = rs.getInt("id"); // get auto_id
      }
      for (int i = 0; i < auto.getOptionSetNum(); i++) {
        name = auto.getOptionSetName(i);
        sql = "insert into optionset (name, auto_id) values('" + name + "'," + autoid + ")";
        statement.executeUpdate(sql); // add to optionset table
        int opsid = 0;
        sql = "select id from optionset where name ='" + name + "';";
        ResultSet rrs = statement.executeQuery(sql);
        while (rrs.next()) {
          opsid = rrs.getInt("id"); // get optionset id
        }
        for (int j = 0; j < auto.getOptionNum(i); j++) {
          name = auto.getOptionName(i, j);
          price = auto.getOptionPrice(i, j);
          sql =
              "insert into options (name, price, option_id) values('"
                  + name
                  + "',"
                  + price
                  + ","
                  + opsid
                  + ")";
          statement.executeUpdate(sql); // add to options table
        }
      }

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 23
0
  /**
   * Method called by the Form panel to delete existing data.
   *
   * @param persistentObject value object to delete
   * @return an ErrorResponse value object in case of errors, VOResponse if the operation is
   *     successfully completed
   */
  public Response deleteRecord(ValueObject persistentObject) throws Exception {
    PreparedStatement stmt = null;
    try {
      stmt = conn.prepareStatement("delete from DEMO4 where TEXT=?");
      DetailTestVO vo = (DetailTestVO) persistentObject;
      stmt.setString(1, vo.getStringValue());
      stmt.execute();

      // this instruction is no more needed: the grid has been linked to the Form (see Form.linkGrid
      // method...)
      //      gridFrame.reloadData();
      return new VOResponse(vo);
    } catch (SQLException ex) {
      ex.printStackTrace();
      return new ErrorResponse(ex.getMessage());
    } finally {
      try {
        stmt.close();
        conn.commit();
      } catch (SQLException ex1) {
      }
    }
  }
Ejemplo n.º 24
0
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter toClient = res.getWriter();
    toClient.println("<!DOCTYPE HTML>");
    toClient.println("<html>");
    toClient.println("<head><title>Books</title></head>");
    toClient.println("<body>");
    toClient.println("<a href=\"index.html\">Home</A>");
    toClient.println("<h2>List of books</h2>");

    HttpSession session = req.getSession(false);
    if (session != null) {
      String name = (String) session.getAttribute("name");
      if (name != null) {
        toClient.println("<h2>name: " + name + "</h2>");
      }
    }

    toClient.print("<form action=\"bookOpinion\" method=GET>");
    toClient.println("<table border='1'>");

    String sql = "Select code, title, author FROM books";
    System.out.println(sql);
    try {
      Statement statement = connection.createStatement();
      ResultSet result = statement.executeQuery(sql);
      while (result.next()) {
        toClient.println("<tr>");
        String codeStr = result.getString("code");
        toClient.println(
            "<td><input type=\"radio\" name=\"book" + "\" value=\"" + codeStr + "\"></td>");
        toClient.println("<td>" + codeStr + "</td>");
        toClient.println("<td>" + result.getString("title") + "</td>");
        toClient.println("<td>" + result.getString("author") + "</td>");
        toClient.println("</tr>");
      }
    } catch (SQLException e) {
      e.printStackTrace();
      System.out.println("Resulset: " + sql + " Exception: " + e);
    }
    toClient.println("</table>");
    toClient.println("<textarea rows=\"8\" cols=\"60\" name=\"comment\"></textarea><BR>");
    toClient.println("<input type=submit>");
    toClient.println("</form>");
    toClient.println("</body>");
    toClient.println("</html>");
    toClient.close();
  }
Ejemplo n.º 25
0
    public boolean insert() {
      PreparedStatement stmt = null;
      try {
        stmt =
            conn.prepareStatement(
                "INSERT OR REPLACE INTO metadatablobs (writingkey, mapkey, blobdata) VALUES(?, ?, ?)");

        stmt.setString(1, this.b64WritingKey);
        stmt.setString(2, this.b64mapkey);
        stmt.setString(3, this.b64blobdata);
        stmt.executeUpdate();
        return true;
      } catch (SQLException sqe) {
        sqe.printStackTrace();
        return false;
      } finally {
        if (stmt != null)
          try {
            stmt.close();
          } catch (SQLException sqe2) {
            sqe2.printStackTrace();
          }
      }
    }
Ejemplo n.º 26
0
 public RowData[] select() {
   PreparedStatement stmt = null;
   try {
     stmt = conn.prepareStatement(selectStatement());
     ResultSet rs = stmt.executeQuery();
     List<RowData> list = new ArrayList<>();
     while (rs.next()) {
       String username = rs.getString("name");
       String b64string = rs.getString(b64DataName());
       list.add(new UserData(username, b64string));
     }
     return list.toArray(new RowData[0]);
   } catch (SQLException sqe) {
     sqe.printStackTrace();
     return null;
   } finally {
     if (stmt != null)
       try {
         stmt.close();
       } catch (SQLException sqe2) {
         sqe2.printStackTrace();
       }
   }
 }
Ejemplo n.º 27
0
 public Iterator<String> execute(String input) {
   try {
     ps.setString(1, input);
     ResultSet rs = ps.executeQuery();
     LinkedList<String> results = new LinkedList<String>();
     while (rs.next()) {
       results.add(rs.getString(1));
     }
     rs.close();
     return results.iterator();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return new EmptyIterator<String>();
 }
Ejemplo n.º 28
0
  // Parse configuration data from given database
  // Read info and write appropriate .ini and .dat files
  // Given classname of JDBC driver, URL of database and user/password
  protected void parseConfigData(
      String driver_classname,
      String datasource_url,
      String username,
      String password,
      String community,
      String node,
      String path) {

    System.out.println("Loading driver " + driver_classname);

    try {
      Class driver = Class.forName(driver_classname);
    } catch (ClassNotFoundException e) {
      System.out.println("Could not load driver : " + driver_classname);
      e.printStackTrace();
    }

    System.out.println("Connecting to the datasource : " + datasource_url);
    try {
      Connection conn = DriverManager.getConnection(datasource_url, username, password);

      Statement stmt = conn.createStatement();

      // Maintain a hashtable of NodeName => Vector of ClusterNames
      Hashtable all_nodes = new Hashtable();
      parseNodeInfo(all_nodes, stmt, community, node);
      dumpNodeInfo(all_nodes, path);

      // Maintain a hashtable of ClusterName => Vector of Plugins
      Hashtable all_clusters = new Hashtable();
      parseClusterInfo(all_clusters, stmt, community, node);
      dumpClusterInfo(all_clusters, path);

      // Maintain a hashtable of OrganizationName => OrganizationData
      Hashtable all_organizations = new Hashtable();
      parseOrganizationInfo(all_organizations, stmt, community, node);
      dumpOrganizationInfo(all_organizations, path);

      conn.close();
    } catch (IOException ioe) {
      System.out.println("IO Exception");
      ioe.printStackTrace();
    } catch (SQLException sqle) {
      System.out.println("SQL Exception");
      sqle.printStackTrace();
    }
  }
 public void store(String cacheEntryName, InputStream inputStream, long expirationDate) {
   try {
     PreparedStatement stmt =
         connection.prepareStatement(
             "INSERT INTO " + tableName + " (id, expiration_date, response) VALUES(?, ?, ?)");
     stmt.setString(1, cacheEntryName);
     stmt.setTimestamp(2, new Timestamp(expirationDate));
     stmt.setCharacterStream(3, new InputStreamReader(inputStream, "UTF-8"), -1);
     stmt.execute();
     stmt.close();
   } catch (SQLException e) {
     e.printStackTrace();
     // ignore
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
     //			won't happen
   }
 }
Ejemplo n.º 30
0
  public String execute() {
    HttpSession session = ServletActionContext.getRequest().getSession();
    if (photo == null) return "setinfo";
    String uploadPath = "/var/www/uploadres";
    String photoName = session.getAttribute("username") + this.getPhotoFileName();
    File toPhotoFile = new File(new File(uploadPath), photoName);

    if (!toPhotoFile.getParentFile().exists()) toPhotoFile.getParentFile().mkdirs();
    try {
      FileUtils.copyFile(photo, toPhotoFile);
      try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        try {
          Connection conn = DriverManager.getConnection(url, user, pwd);
          Statement stmt = conn.createStatement();
          String sql =
              "UPDATE Users SET photo = '"
                  + photoName
                  + "' WHERE username='******'";
          stmt.execute(sql);
        } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return "setinfo";
  }