一、配置需要以下的包:
spring-jdbc.jar
spring-dao.jar
commons-dbcp-1.2.1.jar
mysql-connector-java-5.0.5-bin.jar
将他们放到%RED5_HOME%\lib下即可
二、配置文件:
1、red5-web.properties
加入如下几行:根据你的数据库环境自行修改其值
db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/test
db.username=root
db.password=root
2、red5-web.xml
3、Red5中调用:
1)示例方法,RowMapper方式:
public String getSampleString()
{
//Getting the datasource bean
Object o=scope.getContext().getBean("myDataSource");
JdbcTemplate t=new JdbcTemplate((BasicDataSource)o);
//我的测试数据库为test,数据表为users;
final List l=t.query("SELECT * FROM users;",new RowMapper(){
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return new MappedRow(rs.getInt(1),rs.getString(2));
}
});
//循环读取
final Iterator
String s="";
while(i.hasNext()){
s+=i.next().getName()+";";
}
//return the result for an function
logger.info("------------------------");
System.out.println("------------------------");
System.out.println("Spring jdbc pool worked.");
return s;
}
2)MappedRow:
public class MappedRow {
protected int id;
protected String name;
public MappedRow(int _id,String _name) {
id=_id;
name=_name;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}
以上。