jsp mysql 网上书店源代码

能帮我找到可以用的源代码吗?参考一下有的话把下载地址给我留下谢谢了有好的一定追加分... 能帮我找到可以用的源代码吗?参考一下 有的话把下载地址给我留下
谢谢了 有好的一定追加分
展开
 我来答
nguzlp
2009-05-03 · TA获得超过825个赞
知道小有建树答主
回答量:211
采纳率:0%
帮助的人:208万
展开全部
这些都是我日常用到的类(mysql)

数据库连接类(也叫数据池)
package DBConnection;
import java.sql.*;

public class DBConnectionManager {

private String driverName="com.mysql.jdbc.Driver";
private String url="jdbc:MySQL://localhost:3306/service?useUnicode=true&characterEncoding=GBK";
private String user="root";
private String password="lena";
public void setManager(String newDriverName,String newUrl,String newUser,String newPassword){
driverName=newDriverName;
url=newUrl;
user=newUser;
password=newPassword;
}
public void setDriverName(String newDriverName) {
driverName = newDriverName;
}
public String getDriverName() {
return driverName;
}

public void setUrl(String newUrl) {
url = newUrl;
}
public String getUrl() {
return url;
}
public void setUser(String newUser) {
user = newUser;
}
public String getUser() {
return user;
}
public void setPassword(String newPassword) {
password = newPassword;
}
public String getPassword() {
return password;
}

public Connection getConnection(){
try{
Class.forName(driverName);
return DriverManager.getConnection(url,user,password);
}
catch(Exception e){e.printStackTrace();
return null;
}
}
}
数据库操作类:
package DBConnection;
import java.sql.*;
import DBConnection.DBConnectionManager;

public class DataBase {
protected Connection conn=null;
protected Statement stmt=null;
protected ResultSet rs=null;
protected PreparedStatement pstmt=null;
protected String sql;
protected boolean isConnect=true;
public DataBase(){
try{
sql="";
DBConnectionManager dcm=new DBConnectionManager();
conn=dcm.getConnection();
stmt=conn.createStatement();
}
catch(Exception e){
System.out.println(e);
isConnect=false;
}
}
public Statement getStatement() {
return stmt;
}

public Connection getConnection() {
return conn;
}

public PreparedStatement getPreparedStatement() {
return pstmt;
}

public ResultSet getResultSet() {
return rs;
}

public String getSql() {
return sql;
}

public boolean execute() throws Exception {
return false;
}

public boolean insert() throws Exception {
return false;
}

public boolean update() throws Exception {
return false;
}

public boolean delete() throws Exception {
return false;
}
public boolean query() throws Exception {
return false;
}

public void close() throws SQLException {
if ( stmt != null )
{
stmt.close();
stmt = null;
}
conn.close();
conn = null;
}
}
这个是我自己设计的我要用的类,使用很方便
package DBConnection;

import DBConnection.DataBase;
import java.sql.*;

public class data extends DataBase{
public data(){super();}

public ResultSet select(String sqlString){
try{
rs=stmt.executeQuery(sqlString);
return rs;
}
catch(SQLException e){
System.out.println(e);
return null;
}
}
public boolean edit(String sqlString){
try{
stmt.execute(sqlString);
System.out.println("update success");
return true;
}
catch(SQLException e){
System.out.println(e);
return false;
}
}
public String codeToString(String str)
{//处理中文字符串的函数
try
{
str = new String(str.getBytes("ISO-8859-1"),"GBK");
return str;
}
catch (Exception e)
{
return str;
}
}
}
dugufeiying123
2009-05-04 · TA获得超过289个赞
知道小有建树答主
回答量:329
采纳率:0%
帮助的人:218万
展开全部
package studentInfo;

/* 数据访问组件 */

import java.io.*;
import java.util.*;
import java.sql.*;

public class DBPool{
private static DBPool instance = null;

//取得连接
public static synchronized Connection getConnection() {
if (instance == null){
instance = new DBPool();
}
return instance._getConnection();
}

private DBPool(){
super();
}

private Connection _getConnection(){
try{
String sDBDriver = null;
String sConnection = null;
String sUser = null;
String sPassword = null;

Properties p = new Properties();
InputStream is = getClass().getResourceAsStream("/db.properties");
p.load(is);
sDBDriver = p.getProperty("DBDriver",sDBDriver);
sConnection = p.getProperty("Connection",sConnection);
sUser = p.getProperty("User","");
sPassword = p.getProperty("Password","");

Properties pr = new Properties();
pr.put("user",sUser);
pr.put("password",sPassword);
pr.put("characterEncoding", "GB2312");
pr.put("useUnicode", "TRUE");

Class.forName(sDBDriver).newInstance();
return DriverManager.getConnection(sConnection,pr);
}
catch(Exception se){
System.out.println(se);
return null;
}
}

//释放资源
public static void dbClose(Connection conn,PreparedStatement ps,ResultSet rs)
throws SQLException
{
rs.close();
ps.close();
conn.close();

}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式