資源簡介
通過瀏覽器對數據庫中的表格進行增刪改查,以及對數據庫進行批量刪除

代碼片段和文件信息
package?com.itheima.dao;
import?java.sql.Connection;
import?java.sql.SQLException;
import?java.util.List;
import?org.apache.commons.dbutils.QueryRunner;
import?org.apache.commons.dbutils.handlers.BeanHandler;
import?org.apache.commons.dbutils.handlers.BeanListHandler;
import?com.itheima.domain.Product;
import?com.itheima.utils.C3P0Utils;
public?class?ProductDao?{
public?List?findAll()?throws?SQLException?{
QueryRunner?runner?=?new?QueryRunner(C3P0Utils.getDataSource());
String?sql=“select?*?from?product“;
List?list?=?runner.query(sql?new?BeanListHandler(Product.class));
return?list;
}
public?void?addPro(Product?product)?throws?SQLException?{
QueryRunner?runner?=?new?QueryRunner(C3P0Utils.getDataSource());
String?sql=“insert?into?product?values(???????)“;
object[]?param={product.getPid()product.getPname()product.getMarket_price()
product.getShop_price()product.getPimage()product.getPdate()product.getPdesc()};
int?update?=?runner.update(sql?param);
}
public?void?delProById(String?pid)?throws?SQLException?{
QueryRunner?runner?=?new?QueryRunner(C3P0Utils.getDataSource());
String?sql=“delete?from?product?where?pid?=???“;
runner.update(sql?pid);
}
public?Product?findById(String?pid)?throws?SQLException?{
QueryRunner?runner?=?new?QueryRunner(C3P0Utils.getDataSource());
String?sql=“select?*?from?product?where?pid=?“;
Product?product?=?runner.query(sql?new?BeanHandler<>(Product.class)?pid);
return?product;
}
public?void?updatePro(Product?pro)?throws?SQLException?{
QueryRunner?runner?=?new?QueryRunner(C3P0Utils.getDataSource());
String?sql=“update?product?set?pname=??market_price=??shop_price=??pdate=?“
+?“pdesc=??where?pid=??“;
object[]?params={pro.getPname()pro.getMarket_price()pro.getShop_price()
pro.getPdate()pro.getPdesc()pro.getPid()};
int?update?=?runner.update(sql?params);
}
public?void?delSelectedPro(String[]?pids)?throws?SQLException?{
QueryRunner?runner?=?new?QueryRunner();
//獲取連接
Connection?conn?=?C3P0Utils.getConnection();
String?sql=“delete?from?product?where?pid=?“;
//循環刪除商品信息
for?(int?i?=?0;?i? runner.update(conn?sql?pids[i]);
}
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-06-06?20:30??day10\
?????文件?????????841??2018-05-30?15:45??day10\.classpath
?????文件????????1038??2018-05-30?15:45??day10\.project
?????目錄???????????0??2018-06-06?20:30??day10\.settings\
?????文件?????????567??2018-05-30?15:45??day10\.settings\.jsdtscope
?????文件?????????364??2018-05-30?15:45??day10\.settings\org.eclipse.jdt.core.prefs
?????文件?????????467??2018-05-30?15:45??day10\.settings\org.eclipse.wst.common.component
?????文件?????????345??2018-05-30?15:45??day10\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件??????????49??2018-05-30?15:45??day10\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件???????????6??2018-05-30?15:45??day10\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????目錄???????????0??2018-06-06?20:30??day10\WebContent\
?????目錄???????????0??2018-06-06?20:30??day10\WebContent\me
?????文件??????????39??2018-05-30?15:45??day10\WebContent\me
?????目錄???????????0??2018-06-06?20:30??day10\WebContent\WEB-INF\
?????目錄???????????0??2018-06-06?20:30??day10\WebContent\WEB-INF\lib\
?????文件??????414881??2018-05-29?21:40??day10\WebContent\WEB-INF\lib\c3p0-0.9.2-pre5.jar
?????文件??????232019??2018-05-30?18:52??day10\WebContent\WEB-INF\lib\commons-beanutils-1.8.3.jar
?????文件???????49572??2018-05-29?21:40??day10\WebContent\WEB-INF\lib\commons-dbutils-1.4.jar
?????文件???????60841??2018-05-30?19:05??day10\WebContent\WEB-INF\lib\commons-logging-1.1.1.jar
?????文件???????20682??2018-05-30?16:28??day10\WebContent\WEB-INF\lib\jstl.jar
?????文件??????569855??2018-05-29?21:40??day10\WebContent\WEB-INF\lib\mchange-commons-java-0.2.3.jar
?????文件??????832960??2018-05-29?21:40??day10\WebContent\WEB-INF\lib\mysql-connector-java-5.1.22-bin.jar
?????文件??????393259??2018-05-30?16:28??day10\WebContent\WEB-INF\lib\standard.jar
?????目錄???????????0??2018-06-06?20:30??day10\WebContent\WEB-INF\product\
?????文件????????1121??2018-05-30?18:56??day10\WebContent\WEB-INF\product\add.jsp
?????文件????????2705??2018-05-31?23:07??day10\WebContent\WEB-INF\product\list.jsp
?????文件????????1356??2018-05-30?21:39??day10\WebContent\WEB-INF\product\update.jsp
?????文件????????1006??2018-05-30?16:04??day10\WebContent\WEB-INF\web.xm
?????文件?????????449??2018-05-30?16:05??day10\WebContent\index.jsp
?????目錄???????????0??2018-06-06?20:30??day10\WebContent\products\
?????目錄???????????0??2018-06-06?20:30??day10\WebContent\products\1\
............此處省略83個文件信息
評論
共有 條評論