【Java开源代码栏目提醒】:网学会员为广大网友收集整理了,ysfPromotion.java,希望对大家有所帮助!
package flashRemoting.ysf;
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.sql.*;
import javax.naming.*;
import sun.jdbc.rowset.*;
public class ysfPromotion
implements Serializable {
public ysfPromotion() {}
public ResultSet getBy(Object week_name) throws Exception {
Connection connection = null;
PreparedStatement stmt = null;
ResultSet rs = null;
CachedRowSet crs = new CachedRowSet();
String sql = "SELECT a.*,b.productPic,b.productPicPath FROM promotion a INNER JOIN productDetail b ON a.productName=b.productName Where a.promotionDate = '" + week_name + "'";
try {
Context ctx = (Context) new InitialContext().lookup("java:comp/env");
DataSource ds = (DataSource) ctx.lookup("ysfDb");
connection = ds.getConnection();
stmt = connection.prepareStatement(
sql);
rs = stmt.executeQuery();
crs.populate(rs);
crs.last();
System.out.println("RowSet populated.");
}
catch (Exception e) {
System.out.println(e);
}
finally {
try {
rs.close();
stmt.close();
connection.close();
}
catch (Exception e) {}
}
return crs;
}
public ResultSet getAll() throws Exception {
Connection connection = null;
PreparedStatement stmt = null;
ResultSet rs = null;
CachedRowSet crs = new CachedRowSet();
String sql = "SELECT a.*,b.productPic,b.productPicPath FROM promotion a INNER JOIN productDetail b ON a.productName = b.productName";
System.out.println(sql);
try {
Context ctx = (Context) new InitialContext().lookup("java:comp/env");
DataSource ds = (DataSource) ctx.lookup("ysfDb");
connection = ds.getConnection();
stmt = connection.prepareStatement(sql);
rs = stmt.executeQuery();
crs.populate(rs);
crs.last();
System.out.println("RowSet populated.");
}
catch (Exception e) {
System.out.println(e);
}
finally {
try {
rs.close();
stmt.close();
connection.close();
}
catch (Exception e) {}
}
return crs;
}
}