資源簡介
打分

代碼片段和文件信息
package?com.stx.dao;
import?java.sql.Connection;
import?java.sql.DriverManager;
import?java.sql.ResultSet;
import?java.sql.SQLException;
import?java.sql.Statement;
import?java.util.ArrayList;
import?java.util.List;
import?com.stx.entity.AdminPerson;
public?class?AdminPersonDao?{
//?獲取數(shù)據(jù)庫鏈接
public?Connection?getConn()?{
Connection?connection?=?null;
try?{
//?裝載驅(qū)動程序
Class.forName(“com.mysql.jdbc.Driver“);
//?建立連接其實是創(chuàng)建了一個連接對象
connection?=?DriverManager.getConnection(
“jdbc:mysql://localhost:3306/dafen“?“root“?“root“);
}?catch?(ClassNotFoundException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}?catch?(SQLException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
return?connection;
}
//?增加數(shù)據(jù)方法
public?void?addAdminPerson(String?sql)?{
try?{
//?獲取連接
Connection?connection?=?this.getConn();
//?獲取執(zhí)行者
Statement?stmt?=?connection.createStatement();
//?執(zhí)行操作
stmt.execute(sql);
//?關(guān)閉通道,釋放資源,關(guān)閉的順序:先創(chuàng)建的后關(guān)閉,后創(chuàng)建的先關(guān)閉
stmt.close();
connection.close();
}?catch?(SQLException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
}
//?更新操作
public?void?updateAdminPerson(String?sql)?{
try?{
//?獲取鏈接
Connection?conn?=?getConn();
//?創(chuàng)建執(zhí)行者
Statement?stmt?=?conn.createStatement();
//?執(zhí)行語句
stmt.execute(sql);
//?關(guān)閉鏈接
stmt.close();
conn.close();
}?catch?(SQLException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
}
//?刪除操作
public?void?deleteAdminPerson(String?sql)?{
try?{
//?獲取鏈接
Connection?conn?=?getConn();
//?創(chuàng)建執(zhí)行者
Statement?stmt?=?conn.createStatement();
//?執(zhí)行語句
stmt.execute(sql);
//?關(guān)閉鏈接
stmt.close();
conn.close();
}?catch?(SQLException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
}
//?查詢操作
public?List?selectAdminPerson(String?where)?{
List?list?=?new?ArrayList();
try?{
//?創(chuàng)建連接
Connection?connection?=?getConn();
//?創(chuàng)建執(zhí)行者
Statement?stmt?=?connection.createStatement();
//?執(zhí)行查詢,將查詢結(jié)果放入結(jié)果集
ResultSet?rs?=?stmt.executeQuery(“select?*?from?adminperson?where?1=1?“
+?where);
//?輸出
while?(rs.next())?{
//?創(chuàng)建實體類對象將數(shù)據(jù)庫表中的一行數(shù)據(jù)放入一個對象中
AdminPerson?a=new?AdminPerson();
a.setId(rs.getInt(“id“));
a.setUsername(rs.getString(“username“));
a.setPassword(rs.getString(“password“));
//?將對象放入list
list.add(a);
}
//?關(guān)閉資源
rs.close();
stmt.close();
connection.close();
}?catch?(SQLException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
return?list;
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1089??2016-05-03?19:29??dafen\.classpath
?????文件???????1330??2016-05-04?00:21??dafen\.project
?????文件????????522??2016-05-03?19:29??dafen\.settings\.jsdtscope
?????文件????????364??2016-05-03?19:29??dafen\.settings\org.eclipse.jdt.core.prefs
?????文件????????474??2016-05-03?19:29??dafen\.settings\org.eclipse.wst.common.component
?????文件????????412??2016-05-03?19:29??dafen\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件?????????49??2016-05-03?19:29??dafen\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件??????????6??2016-05-03?19:29??dafen\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????文件???????2999??2016-05-03?23:59??dafen\src\com\stx\dao\AdminPersonDao.java
?????文件???????2874??2016-05-04?00:02??dafen\src\com\stx\dao\PwpersonDao.java
?????文件???????2936??2016-05-04?00:10??dafen\src\com\stx\dao\XspersonDao.java
?????文件????????490??2016-05-03?23:12??dafen\src\com\stx\entity\AdminPerson.java
?????文件????????487??2016-05-03?23:55??dafen\src\com\stx\entity\Pwperson.java
?????文件????????704??2016-05-04?00:08??dafen\src\com\stx\entity\Xsperson.java
?????文件????????906??2016-04-19?16:38??dafen\src\com\stx\filter\EncodeingFilter.java
?????文件???????2335??2016-06-16?11:09??dafen\src\com\stx\servlet\LoginServlet.java
?????文件??????83306??2016-05-03?15:15??dafen\WebRoot\images\8.jpg
?????文件???????2207??2016-06-16?10:26??dafen\WebRoot\index.jsp
?????文件?????????39??2016-05-03?19:29??dafen\WebRoot\me
?????文件????????455??2016-04-26?20:59??dafen\WebRoot\page\bottom.jsp
?????文件???????1681??2016-06-16?11:01??dafen\WebRoot\page\main.jsp
?????文件???????1540??2016-05-03?15:02??dafen\WebRoot\page\top.jsp
?????文件??????96381??2016-05-03?19:36??dafen\WebRoot\pintuer\jquery.js
?????文件?????148934??2016-05-03?19:36??dafen\WebRoot\pintuer\pintuer.css
?????文件??????21171??2016-05-03?19:36??dafen\WebRoot\pintuer\pintuer.js
?????文件???????4672??2016-05-03?19:36??dafen\WebRoot\pintuer\readme.txt
?????文件????????214??2016-05-03?19:36??dafen\WebRoot\pintuer\拼圖Pintuer-跨屏響應(yīng)式布局前端開發(fā)CSS框架.url
?????文件???????2998??2016-11-15?12:32??dafen\WebRoot\WEB-INF\classes\com\stx\dao\AdminPersonDao.class
?????文件???????2968??2016-11-15?12:32??dafen\WebRoot\WEB-INF\classes\com\stx\dao\PwpersonDao.class
?????文件???????3050??2016-11-15?12:32??dafen\WebRoot\WEB-INF\classes\com\stx\dao\XspersonDao.class
............此處省略37個文件信息
評論
共有 條評論