Я прошел следующее руководство по Spring
http://www.tutorialspoint.com/spring/ca ... cedure.htm
Все работает, единственная проблема заключается в том, что я получаю следующее сообщение.
Apr 22, 2016 3:50:51 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5910e440: startup date [Fri Apr 22 15:50:51 MDT 2016]; root of context hierarchy
Apr 22, 2016 3:50:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Apr 22, 2016 3:50:51 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: net.sourceforge.jtds.jdbc.Driver
----Listing Record with ID = 2 -----
Apr 22, 2016 3:50:52 PM org.springframework.jdbc.core.metadata.CallMetaDataContext matchInParameterValuesWithCallParameters
WARNING: Unable to locate the corresponding parameter value for 'outName' within the parameter values provided: [inID]
Apr 22, 2016 3:50:52 PM org.springframework.jdbc.core.metadata.CallMetaDataContext matchInParameterValuesWithCallParameters
WARNING: Unable to locate the corresponding parameter value for 'outAge' within the parameter values provided: [inID]
ID : 3, Name : Ayan, Age : 15
Единственная разница в том, что я использую MSSQL. Как видите, результаты возвращаются. Я даже передал другой параметр, и значение изменилось, поэтому я знаю, что он работает. Я просто не понимаю, почему я получаю эти сообщения. Я проверил, что имя параметра соответствует тому, что находится в классе.
package com.tutorialspoint;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.tutorialspoint.StudentJDBCTemplate;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("Beans.xml");
StudentJDBCTemplate studentJDBCTemplate =
(StudentJDBCTemplate)context.getBean("studentJDBCTemplate");
/*
System.out.println("------Records Creation--------" );
studentJDBCTemplate.create("Zara", 11);
studentJDBCTemplate.create("Nuha", 2);
studentJDBCTemplate.create("Ayan", 15);
System.out.println("------Listing Multiple Records--------" );
List students = studentJDBCTemplate.listStudents();
for (Student record : students) {
System.out.print("ID : " + record.getId() );
System.out.print(", Name : " + record.getName() );
System.out.println(", Age : " + record.getAge());
}
*/
System.out.println("----Listing Record with ID = 2 -----" );
Student student = studentJDBCTemplate.getStudent(3);
System.out.print("ID : " + student.getId() );
System.out.print(", Name : " + student.getName() );
System.out.println(", Age : " + student.getAge());
}
}
package com.tutorialspoint;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
public class StudentMapper implements RowMapper {
public Student mapRow(ResultSet rs, int rowNum) throws SQLException {
Student student = new Student();
student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setAge(rs.getInt("age"));
return student;
}
}
package com.tutorialspoint;
import java.util.Map;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
public class StudentJDBCTemplate implements StudentDAO {
private DataSource dataSource;
private SimpleJdbcCall jdbcCall;
public void setDataSource(DataSource dataSource){
this.dataSource = dataSource;
this.jdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("getRecord");
}
public void create(String name, Integer age){
JdbcTemplate jdbcTemplateObject = new JdbcTemplate(dataSource);
String SQL = "INSERT INTO Student(name,age) VALUES (?,?)";
jdbcTemplateObject.update(SQL,name,age);
System.out.println("Created Record Name = " + name + " Age = " + age);
return;
}
public Student getStudent(Integer id){
SqlParameterSource in = new MapSqlParameterSource().addValue("inID", id);
Map out = jdbcCall.execute(in);
Student student = new Student();
student.setId(id);
student.setName((String) out.get("outName"));
student.setAge((Integer) out.get("outAge"));
return student;
}
public List listStudents(){
String SQL = "SELECT * FROM Student";
JdbcTemplate jdbcTemplateObject = new JdbcTemplate(dataSource);
List students = jdbcTemplateObject.query(SQL, new StudentMapper());
return students;
}
}
package com.tutorialspoint;
public class Student {
private Integer age;
private String name;
private Integer id;
public void setAge(Integer age) {
this.age = age;
}
public Integer getAge() {
return age;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
}
Подробнее здесь: https://stackoverflow.com/questions/368 ... lling-stor
Получение сообщения Невозможно найти соответствующий параметр при вызове хранимой процедуры ⇐ JAVA
Программисты JAVA общаются здесь
1761914425
Anonymous
Я прошел следующее руководство по Spring
http://www.tutorialspoint.com/spring/calling_stored_procedure.htm
Все работает, единственная проблема заключается в том, что я получаю следующее сообщение.
Apr 22, 2016 3:50:51 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5910e440: startup date [Fri Apr 22 15:50:51 MDT 2016]; root of context hierarchy
Apr 22, 2016 3:50:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Apr 22, 2016 3:50:51 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: net.sourceforge.jtds.jdbc.Driver
----Listing Record with ID = 2 -----
Apr 22, 2016 3:50:52 PM org.springframework.jdbc.core.metadata.CallMetaDataContext matchInParameterValuesWithCallParameters
WARNING: Unable to locate the corresponding parameter value for 'outName' within the parameter values provided: [inID]
Apr 22, 2016 3:50:52 PM org.springframework.jdbc.core.metadata.CallMetaDataContext matchInParameterValuesWithCallParameters
WARNING: Unable to locate the corresponding parameter value for 'outAge' within the parameter values provided: [inID]
ID : 3, Name : Ayan, Age : 15
Единственная разница в том, что я использую MSSQL. Как видите, результаты возвращаются. Я даже передал другой параметр, и значение изменилось, поэтому я знаю, что он работает. Я просто не понимаю, почему я получаю эти сообщения. Я проверил, что имя параметра соответствует тому, что находится в классе.
package com.tutorialspoint;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.tutorialspoint.StudentJDBCTemplate;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("Beans.xml");
StudentJDBCTemplate studentJDBCTemplate =
(StudentJDBCTemplate)context.getBean("studentJDBCTemplate");
/*
System.out.println("------Records Creation--------" );
studentJDBCTemplate.create("Zara", 11);
studentJDBCTemplate.create("Nuha", 2);
studentJDBCTemplate.create("Ayan", 15);
System.out.println("------Listing Multiple Records--------" );
List students = studentJDBCTemplate.listStudents();
for (Student record : students) {
System.out.print("ID : " + record.getId() );
System.out.print(", Name : " + record.getName() );
System.out.println(", Age : " + record.getAge());
}
*/
System.out.println("----Listing Record with ID = 2 -----" );
Student student = studentJDBCTemplate.getStudent(3);
System.out.print("ID : " + student.getId() );
System.out.print(", Name : " + student.getName() );
System.out.println(", Age : " + student.getAge());
}
}
package com.tutorialspoint;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
public class StudentMapper implements RowMapper {
public Student mapRow(ResultSet rs, int rowNum) throws SQLException {
Student student = new Student();
student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setAge(rs.getInt("age"));
return student;
}
}
package com.tutorialspoint;
import java.util.Map;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
public class StudentJDBCTemplate implements StudentDAO {
private DataSource dataSource;
private SimpleJdbcCall jdbcCall;
public void setDataSource(DataSource dataSource){
this.dataSource = dataSource;
this.jdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("getRecord");
}
public void create(String name, Integer age){
JdbcTemplate jdbcTemplateObject = new JdbcTemplate(dataSource);
String SQL = "INSERT INTO Student(name,age) VALUES (?,?)";
jdbcTemplateObject.update(SQL,name,age);
System.out.println("Created Record Name = " + name + " Age = " + age);
return;
}
public Student getStudent(Integer id){
SqlParameterSource in = new MapSqlParameterSource().addValue("inID", id);
Map out = jdbcCall.execute(in);
Student student = new Student();
student.setId(id);
student.setName((String) out.get("outName"));
student.setAge((Integer) out.get("outAge"));
return student;
}
public List listStudents(){
String SQL = "SELECT * FROM Student";
JdbcTemplate jdbcTemplateObject = new JdbcTemplate(dataSource);
List students = jdbcTemplateObject.query(SQL, new StudentMapper());
return students;
}
}
package com.tutorialspoint;
public class Student {
private Integer age;
private String name;
private Integer id;
public void setAge(Integer age) {
this.age = age;
}
public Integer getAge() {
return age;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/36804032/receiving-message-unable-to-locate-the-corresponding-parameter-when-calling-stor[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия