Example usage for java.sql PreparedStatement setString

List of usage examples for java.sql PreparedStatement setString

Introduction

In this page you can find the example usage for java.sql PreparedStatement setString.

Prototype

void setString(int parameterIndex, String x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java String value.

Usage

From source file:generate.ShowConceptMapAction.java

public String execute() throws ClassNotFoundException, SQLException, IOException {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Major", "root", "pass");
    PreparedStatement ps = con
            .prepareStatement("SELECT * from conceptmapdata where chapter_name = ? and section_name = ?");
    ps.setString(1, getKey1());
    ps.setString(2, getKey2());//  ww  w.  ja v  a  2 s  .co  m
    System.out.println(getKey1());
    System.out.println(getKey2());
    ResultSet rs = ps.executeQuery();
    while (rs.next()) {

        setData(rs.getString("output_text"));
    }
    try {

        FileWriter file = new FileWriter("/home/chanakya/NetBeansProjects/Concepto/web/new_graph.json");
        file.write(getData());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    return SUCCESS;
}

From source file:org.sakaiproject.imagegallery.integration.standalone.FileLibraryStandalone.java

/**
 * @see org.sakaiproject.imagegallery.integration.FileLibraryService#storeImageFile(org.springframework.web.multipart.MultipartFile)
 *//*from ww w .j  a va2s  . com*/
@Transactional
public ImageFile storeImageFile(final MultipartFile sourceImageFile) {
    final String filename = sourceImageFile.getOriginalFilename();
    final String fileId = contextService.getCurrentContextUid() + "/" + filename;
    final String contentType = sourceImageFile.getContentType();

    ImageFile imageFile = new ImageFile();
    imageFile.setContentType(contentType);
    imageFile.setFilename(filename);
    imageFile.setFileId(fileId);
    imageFile.setDataUrl(urlPrefix + fileId);

    jdbcTemplate.getJdbcOperations().execute(
            "insert into IMAGE_GALLERY_STANDALONE_FILES_T (FILE_ID, CONTENT_TYPE, CONTENT) VALUES (?, ?, ?)",
            new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) {
                protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
                    ps.setString(1, fileId);
                    ps.setString(2, contentType);
                    try {
                        lobCreator.setBlobAsBinaryStream(ps, 3, sourceImageFile.getInputStream(),
                                (int) sourceImageFile.getSize());
                    } catch (IOException e) {
                        log.error("Error copying binary data from file " + filename, e);
                    }
                }
            });

    return imageFile;
}

From source file:net.freechoice.dao.impl.DaoTag.java

@Warning(values = { "Injection" })
@Override//from   w w w  .j a va2 s.c o m
public List<FC_Tag> getTagsByName(final String name) {

    return getJdbcTemplate().query(new PreparedStatementCreator() {

        @Override
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement ps = con
                    .prepareStatement(SELECT_FROM_FC_TAG + " where is_valid = true and content = ?");
            ps.setString(1, name);
            return ps;
        }
    }, mapper);
}

From source file:com.spend.spendService.MainPage.java

private void createSearchQueue() {
    try {/*from w  w w  .j  av  a 2s .  com*/
        String st = getSearchQuery();
        String[] selist = getSearchEngineNamesArray();

        for (Object se : selist) {
            String SQLi = "INSERT INTO searchqueue (searchText,searchEngineName, disabled) VALUES (?,?,0)";
            PreparedStatement pstmt = con2.prepareStatement(SQLi);
            pstmt.setString(1, st);
            pstmt.setString(2, se.toString());

            pstmt.executeUpdate();
            pstmt.close();
        }
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:Modelo.FileUploadView.java

/**
 *
 * @param archivo//from   w  w w.ja  va2  s .c o m
 * @return
 */
public boolean registrarArchivo(UploadedFile archivo) {
    ResultSet rs = null;
    Statement cmd = null;
    boolean ejecuto;

    try {
        cmd = con.createStatement();

        String data = encodeFileToBase64Binary(archivo);

        // System.out.println("\n \n \n el archivo es: \n"+data+"\n \n ");

        PreparedStatement stment = con.prepareStatement("Insert into archivos value(?)");
        stment.setString(1, data);
        stment.execute();

        //ejecuto = cmd.execute("INSERT INTO archivos(longdata) values(" +data+ ");");

        System.out.println("Guardado con exito");
        return true;
        // rs.close();
    } catch (Exception e) {
        System.out.println("SQLException ejecutando sentencia: " + e.getMessage());
        return false;
    }
}

From source file:dao.MaterialDaoImplem.java

@Override
public int insertMaterial(Material material) {
    try (Connection connection = dataSource.getConnection()) {
        String query = ("INSERT INTO Material (name, weight, manufacturer,cost,quantity) values(?,?,?,?,?)");
        PreparedStatement stat = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
        stat.setString(1, material.getName());
        stat.setInt(2, material.getWeight());
        stat.setString(3, material.getManufacturer());
        stat.setInt(4, material.getCost());
        stat.setInt(5, material.getQuantity());
        stat.execute();// www  . j a  v  a  2s.c  o  m
        ResultSet res = stat.getGeneratedKeys();
        if (res.next()) {
            return res.getInt(1);
        } else {
            throw new RuntimeException("? ?    ");
        }
    } catch (Exception e) {
        throw new RuntimeException("Error:insertMaterial", e);
    }
}

From source file:cai.flow.packets.V8_FlowDstPrefix.java

void fill_specific(PreparedStatement add_raw_stm) throws SQLException {
    add_raw_stm.setString(13, Util.str_addr(dst_prefix));
    add_raw_stm.setInt(14, (int) dst_mask);
    add_raw_stm.setInt(15, (int) dst_as);
    add_raw_stm.setInt(16, (int) output);
    add_raw_stm.setString(17, Params.getCurrentTime());
}

From source file:com.wso2telco.gsma.authenticators.DBUtils.java

/**
 * Get prompt data/*  w w w. ja va  2s. c o  m*/
 *
 * @param scope
 * @param prompt
 * @param isLoginHintExists
 * @return PromptData
 */
public static PromptData getPromptData(String scope, String prompt, Boolean isLoginHintExists) {
    PromptData promptData = new PromptData();
    Connection connection = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    String sql = "SELECT * FROM prompt_configuration WHERE scope = ? AND prompt_value = ? AND is_login_hint_exists = ?";

    try {
        connection = getConnectDBConnection();
        ps = connection.prepareStatement(sql);
        ps.setString(1, scope);
        ps.setString(2, prompt);
        ps.setBoolean(3, isLoginHintExists);
        rs = ps.executeQuery();
        while (rs.next()) {
            promptData.setScope(rs.getString("scope"));
            promptData.setLoginHintExists(rs.getBoolean("is_login_hint_exists"));
            promptData.setPromptValue(rs.getString("prompt_value"));
            promptData.setBehaviour(PromptData.behaviorTypes.valueOf(rs.getString("behaviour")));
        }
    } catch (SQLException ex) {
        handleException("Error while retrieving Propmt Data ", ex);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, rs, ps);
        return promptData;
    }
}

From source file:cai.flow.packets.V8_FlowSrcPrefix.java

void fill_specific(PreparedStatement add_raw_stm) throws SQLException {
    add_raw_stm.setString(13, Util.str_addr(src_prefix));
    add_raw_stm.setInt(14, (int) src_mask);
    add_raw_stm.setInt(15, (int) src_as);
    add_raw_stm.setInt(16, (int) input);
    add_raw_stm.setString(17, Params.getCurrentTime());
}