购物车项目(MVC没用任何框架)

2021-04-20 22:26

阅读:353

标签:jsp   大连   最小   color   code   tac   port   print   close   

1.先了解一个思路就是dao-model-service-jsp

一个流程的东西

2.项目所需的jar包 

 

 

技术图片

 

 自己在网上都可以找的jar包

3.需要将c3p0的配置文件写入classpath路径下面

文件名:c3p0-config.xml

xml version="1.0" encoding="UTF-8"?>
c3p0-config>
    default-config>
        property name="driverClass">com.mysql.jdbc.Driverproperty>
        property name="jdbcUrl">jdbc:mysql://localhost:3306/bookstore
        property>
        property name="user">rootproperty>
        property name="password">rootproperty>
        
        property name="initialPoolSize">10property>
        
        
        property name="maxIdleTime">60property>

        
        property name="maxPoolSize">25property>
        
        
        property name="minPoolSize">10property>
    default-config>
c3p0-config>

4.c3p0untils文件

package bookstore.untils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

//数据库连接成功
public class C3P0Utils {
    private static DataSource ds  = new ComboPooledDataSource();
    /**
     * 返回一个数据源,然后得到一个数据库连接
     * @return
     */
    public static DataSource getDataSource(){
        return ds;
    }
    /*
     * 返回一个连接
     */
    public static Connection getConnection(){
        try {
            return ds.getConnection();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            throw new RuntimeException("服务器错误");
        }
    }
    public static void closeAll(Connection conn,Statement statement,ResultSet resultSet){
        if(resultSet != null){
            try {
                resultSet.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            resultSet = null;
        }
        if(statement != null){
            try {
                statement.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            statement = null;
        }
        if(conn != null){
            try {
                conn.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                conn = null;
            }
        }
    }
}

 

购物车项目(MVC没用任何框架)

标签:jsp   大连   最小   color   code   tac   port   print   close   

原文地址:https://www.cnblogs.com/whr-blogs/p/12256691.html


评论


亲,登录后才可以留言!