what is the solution of error like this
Error creating bean with name 'template' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'data' of bean class [org.springframework.jdbc.core.JdbcTemplate]: Bean property 'data' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
if the code is cose is as down
person class
public class person {
private int id;
private String fname;
private String lname;
private int age;
private String address;
private String phone;
public person(String fname, String lname, int age, String address, String phone) {
this.fname=fname;
this.lname=lname;
this.age=age;
this.address=address;
this.fname=phone;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
DataBaseInfo class
import org.springframework.jdbc.core.JdbcTemplate;
public class DataBaseInfo {
private JdbcTemplate template;
public JdbcTemplate getTemplate() {
return template;
}
public void setTemplate(JdbcTemplate template) {
this.template = template;
}
public int insertPerson(person p) throws Exception {
String inserData="insert into person values("+p.getFname()+","+p.getLname()+","+p.getAge()+","+p.getAddress()+","+p.getPhone()+")";
return template.update(inserData);
}
public int updatePerson(person p) throws Exception {
String updateData="update person('fname','lname','age','address','phone') set values("+p.getFname()+","+p.getLname()+","+p.getAge()+","+p.getAddress()+","+p.getPhone()+") ";
return template.update(updateData);
}
public int deletePerson(person p ) throws Exception {
String deleteData="delet from person where ('id= "+p.getId()+"')";
return template.update(deleteData);
}
public int selectAllPerson() throws Exception {
String selectAllData="select * from person ";
return template.update(selectAllData);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="connect" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/spring"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="template" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="data" value="connect"></property>
</bean>
<bean id="dbinfo" class="com.jdbcSpring.dao.DataBaseInfo">
<property name="dbinfo" value="jdbcTemp"></property>
</bean>
</beans>
testJdbc class for checking the codes
package com.jdbcSpring.dao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class testJdbc {
public static void main(String[] args) {
try {
ApplicationContext cont= new ClassPathXmlApplicationContext("applicationContext.xml");
DataBaseInfo dao=( DataBaseInfo) cont.getBean("dbinfo");
int insert=dao.insertPerson(new person("yousuf","arar",35,"pisa","31234567"));
System.out.println(insert);
}catch (Exception e) {}
}
}
The result was the error which is in the beggining what is the solution if you know please write the
in the comments down
thank you
1 Comments
A list of all the best wordpress sports themes in one place. Includes themes for sports clubs, sports magazines, and even sites about your favorite team.
ReplyDelete