Source Code : Use Mapped Object after database Connection close
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Use Mapped Object after database Connection close
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.RowSetDynaClass;
import java.util.Iterator;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.PreparedStatement;
public class DynaBeansExampleV3 {
public static void main(String args[]) throws Exception {
Connection conn = getConnection();
PreparedStatement ps =
conn.prepareStatement(
"SELECT * from movie, person " +
"WHERE movie.director = person.Id");
ResultSet rs = ps.executeQuery();
RowSetDynaClass rsdc = new RowSetDynaClass(rs);
conn.close();
Iterator itr = rsdc.getRows().iterator();
while(itr.hasNext()) {
DynaBean bean = (DynaBean)itr.next();
System.err.println(bean.get("title"));
}
}
private static Connection getConnection() throws Exception {
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName("com.mysql.jdbc.Driver");
bds.setUrl("jdbc:mysql://localhost/commons");
bds.setUsername("root");
bds.setPassword("");
// bds.setInitialSize(5);
return bds.getConnection();
}
}
Thank with us