zoukankan      html  css  js  c++  java
  • jdbc调用mysql存储过程

    public static void updateMtBeginTimeIsSix() {
    		Connection connection = null;
    		CallableStatement cs = null;
    		try {
    			connection = DataSource.getInstance().getConnection();
    			cs = connection.prepareCall("{call update_mt_begin_time_is_six()}");
    			cs.execute();
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			try {
    				if (connection != null) {
    					connection.close();
    				}
    				if (cs != null) {
    					cs.close();
    				}
    			} catch (Exception e2) {
    				e2.printStackTrace();
    			}
    
    		}
    	}
    public static void SubjectOne(String beginDateStr, String endDateStr) {
    		Connection connection = null;
    		CallableStatement cs = null;
    		try {
    			connection = DataSource.getInstance().getConnection();
    			cs = connection.prepareCall("{call queryDataForSubject1(?,?)}");
    			cs.setInt(1, Integer.parseInt(beginDateStr));
    			cs.setInt(2, Integer.parseInt(endDateStr));
    			cs.execute();
    			System.out.println(cs);
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			try {
    				if (connection != null) {
    					connection.close();
    				}
    				if (cs != null) {
    					cs.close();
    				}
    			} catch (Exception e2) {
    				e2.printStackTrace();
    			}
    		}
    	}

    数据源c3p0

    public class DataSource {
    
        private static DataSource datasource;
        private ComboPooledDataSource cpds;
    
        private DataSource() throws IOException, SQLException, PropertyVetoException {
            cpds = new ComboPooledDataSource();
            cpds.setDriverClass("com.mysql.jdbc.Driver"); 
            cpds.setJdbcUrl("jdbc:mysql://localhost:3306/stopsix_two_phase");
            cpds.setUser("root");
            cpds.setPassword("root");
            cpds.setMinPoolSize(5);
            cpds.setAcquireIncrement(5); 
            cpds.setMaxPoolSize(20); 
        }
    
        public static DataSource getInstance() throws IOException, SQLException, PropertyVetoException { 
            if (datasource == null) {
                datasource = new DataSource();
                return datasource;
            } else {
                return datasource;
            }
        }
    
        public Connection getConnection() throws SQLException {
            return this.cpds.getConnection();
        }
    
    }
    
  • 相关阅读:
    linux systemctl 命令详解
    nginx 与 php-fpm 通信配置
    yum Install PHP 7 on CentOS 7 (英文-转载)
    解决在idea中创建spring boot项目start.spring.io初始化失败的问题
    MongoDB学习5:模型设计和设计模式
    MongoDB学习4:MongoDB复制集机制和原理,搭建复制集
    `curl -L` 解决 GitHub 的 raw.githubusercontent.com 无法连接问题
    用 Hugo 快速搭建博客
    针对多系统时间不一致
    kali 下的邮件发送工具 swaks
  • 原文地址:https://www.cnblogs.com/liclBlog/p/15349568.html
Copyright © 2011-2022 走看看