Spring Framework SqlParameter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework SqlParameter class.

This code example shows how to use the following methods:
		source.getValue("pechorin was right!");
	} 
 
	@Test
	public void sqlParameterValueRegistersSqlType() throws Exception {
		MapSqlParameterSource msps = new MapSqlParameterSource("FOO", new SqlParameterValue(2, "Foo"));
		assertEquals("Correct SQL Type not registered", 2, msps.getSqlType("FOO"));
		MapSqlParameterSource msps2 = new MapSqlParameterSource();
		msps2.addValues(msps.getValues());
		assertEquals("Correct SQL Type not registered", 2, msps2.getSqlType("FOO"));
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:getName, getScale, getSqlType
		SqlParameter parameter1 = sqlParametersAsList.get(0);
		SqlParameter parameter2 = sqlParametersAsList.get(1);
		SqlParameter parameter3 = sqlParametersAsList.get(2);
		SqlParameter parameter4 = sqlParametersAsList.get(3);
 
		assertEquals("username",    parameter1.getName());
		assertEquals("password",    parameter2.getName());
		assertEquals("age",         parameter3.getName());
		assertEquals("description", parameter4.getName());
 
		assertNull("Expect that the scale is null.", parameter1.getScale());
		assertNull("Expect that the scale is null.", parameter2.getScale());
		assertEquals("Expect that the scale is 5.", Integer.valueOf(5),  parameter3.getScale());
		assertNull("Expect that the scale is null.", parameter4.getScale());
 
		assertEquals("SqlType is ", Types.VARCHAR, parameter1.getSqlType());
		assertEquals("SqlType is ", Types.VARCHAR, parameter2.getSqlType());
		assertEquals("SqlType is ", Types.INTEGER, parameter3.getSqlType());
		assertEquals("SqlType is ", Types.VARCHAR, parameter4.getSqlType());
 
		assertTrue(parameter1 instanceof SqlParameter);
6
CodeRank
This code example shows how to use the following methods:getName, getScale, getSqlType
		SqlParameter parameter4 = sqlParametersAsList.get(3);
 
		assertEquals("username",    parameter1.getName());
		assertEquals("password",    parameter2.getName());
		assertEquals("age",         parameter3.getName());
		assertEquals("description", parameter4.getName());
 
		assertNull("Expect that the scale is null.", parameter1.getScale());
		assertNull("Expect that the scale is null.", parameter2.getScale());
		assertEquals("Expect that the scale is 5.", Integer.valueOf(5),  parameter3.getScale());
		assertNull("Expect that the scale is null.", parameter4.getScale());
 
		assertEquals("SqlType is ", Types.VARCHAR, parameter1.getSqlType());
		assertEquals("SqlType is ", Types.VARCHAR, parameter2.getSqlType());
		assertEquals("SqlType is ", Types.INTEGER, parameter3.getSqlType());
		assertEquals("SqlType is ", Types.VARCHAR, parameter4.getSqlType());
 
		assertTrue(parameter1 instanceof SqlParameter);
		assertTrue(parameter2 instanceof SqlOutParameter);
		assertTrue(parameter3 instanceof SqlInOutParameter);
		assertTrue(parameter4 instanceof SqlParameter);
6
CodeRank
This code example shows how to use the following methods:
	public void testUnnamedParameterHandling() throws Exception {
		final String MY_PROC = "my_proc";
		SimpleJdbcCall sproc = new SimpleJdbcCall(dataSource).withProcedureName(MY_PROC);
		// Shouldn't succeed in adding unnamed parameter 
		thrown.expect(InvalidDataAccessApiUsageException.class);
		sproc.addDeclaredParameter(new SqlParameter(1));
	} 
 
	@Test
	public void testAddInvoiceProcWithoutMetaDataUsingMapParamSource() throws Exception {
		initializeAddInvoiceWithoutMetaData(false); 
		SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withProcedureName("add_invoice");
		adder.declareParameters(
				new SqlParameter("amount", Types.INTEGER),
				new SqlParameter("custid", Types.INTEGER),
				new SqlOutParameter("newid",
				Types.INTEGER));
		Number newId = adder.executeObject(Number.class, new MapSqlParameterSource().
				addValue("amount", 1103).
				addValue("custid", 3));
6
CodeRank
This code example shows how to use the following methods:
	 */ 
	class MyQueryClass extends MappingSqlQuery<Address> { 
 
		public MyQueryClass(DataSource dataSource, String sql) { 
			super(dataSource, sql); 
			this.declareParameter(new SqlParameter(Types.INTEGER)); 
		} 
 
		/** 
		 * This the implementation of the MappingSqlQuery abstract method. This 
		 * method creates and returns a instance of our value object associated 
		 * with the table / select statement. 
		 *  
		 * @param rs 
		 *            This is the current ResultSet 
		 * @param rowNum 
		 *            The rowNum 
		 * @throws SQLException 
		 *             This is taken care of by the Spring stuff... 
		 */ 
6
CodeRank
This code example shows how to use the following methods:
	public NodeValueSearchByKeyAndValue(DataSource dataSource) { 
		setDataSource(dataSource); 
		setSql("SELECT DISTINCT v, valuecount FROM keyvalues WHERE lower(k) = lower(?) " 
				+ "AND lower(v) LIKE lower(?) ORDER BY valuecount DESC LIMIT 20"); 
		declareParameter(new SqlParameter(Types.VARCHAR)); 
		declareParameter(new SqlParameter(Types.VARCHAR)); 
	} 
} 
5
CodeRank
This code example shows how to use the following methods:
	@Autowired 
	public NodeValueSearchByKey(DataSource dataSource) { 
		setDataSource(dataSource); 
 
		setSql("SELECT DISTINCT k, 0 FROM keyvalues WHERE lower(k) LIKE lower(?) ORDER BY k LIMIT 20"); 
		declareParameter(new SqlParameter(Types.VARCHAR)); 
	} 
} 
5
CodeRank
This code example shows how to use the following methods:
    private class GetDocSrc extends MappingSqlQuery { 
         
        public GetDocSrc(DataSource dataSource) { 
            setDataSource(dataSource); 
            setSql(DEF_GET_DOC_SRC_QUERY); 
            declareParameter(new SqlParameter(Types.VARCHAR)); 
            compile(); 
        } //- GetDocSrc.GetDocSrc 
         
        public Document mapRow(ResultSet rs, int rowNum) throws SQLException { 
            Document doc = new Document(); 
            doc.setSource(Document.TITLE_KEY, rs.getString("title")); 
            doc.setSource(Document.ABSTRACT_KEY, rs.getString("abstract")); 
            doc.setSource(Document.YEAR_KEY, rs.getString("year")); 
            doc.setSource(Document.VENUE_KEY, rs.getString("venue")); 
            doc.setSource(Document.VEN_TYPE_KEY, 
                    rs.getString("venueType")); 
            doc.setSource(Document.PAGES_KEY, rs.getString("pages")); 
            doc.setSource(Document.VOL_KEY, rs.getString("volume")); 
            doc.setSource(Document.NUM_KEY, rs.getString("number")); 
1
CodeRank
This code example shows how to use the following methods:
            super(ds, "UPDATE owners SET first_name=?,last_name=?,address=?,city=?,telephone=?,version=? WHERE id=?"); 
            declareParameter(new SqlParameter(Types.VARCHAR)); 
            declareParameter(new SqlParameter(Types.VARCHAR)); 
            declareParameter(new SqlParameter(Types.VARCHAR)); 
            declareParameter(new SqlParameter(Types.VARCHAR)); 
            declareParameter(new SqlParameter(Types.VARCHAR)); 
            declareParameter(new SqlParameter(Types.TIMESTAMP)); 
            declareParameter(new SqlParameter(Types.INTEGER)); 
            compile(); 
        } 
 
        /** 
         * Method to update an <code>Owner</code>'s data. 
         *  
         * @param owner 
         *            to update 
         * @return the number of rows affected by the update 
         */ 
        protected int update(Owner owner) { 
            return this.update(new Object[] { owner.getFirstName(), owner.getLastName(), owner.getAddress(), 
2
CodeRank
This code example shows how to use the following methods:
    private class UpdateCiteULikeRecord extends SqlUpdate { 
 
        public UpdateCiteULikeRecord(DataSource dataSource) { 
            setDataSource(dataSource); 
            setSql(DEF_UPDATE_CITEULIKE_RECORD_QUERY); 
            declareParameter(new SqlParameter(Types.VARCHAR)); 
            declareParameter(new SqlParameter(Types.BIGINT)); 
            compile(); 
        } //- UpdateCiteULikeRecord.InsertDBLPRecord 
         
        public int run(CiteULike record) { 
            Object[] params = new Object[] { 
                    record.getCiteSeerXID(), 
                    record.getCiteulikeID() 
            }; 
            return update(params); 
        } //- UpdateCiteULikeRecord.run 
    } //- class UpdateCiteULikeRecord 
     
    private static final String DEF_GET_CITEULIKE_RECORD_BY_DOI_QUERY = 
2
CodeRank
See Code Examples for Spring Framework SqlParameter Methods: