No suitable driver

No suitable driver

package com.imooc.jdbc.demo2;


import java.sql.Connection;

import java.sql.Date;

import java.sql.PreparedStatement;

import java.sql.ResultSet;


import org.junit.Test;


import com.imooc.jdbc.utils.JDBCutils;

import com.mchange.v2.c3p0.ComboPooledDataSource;



/**

 * 连接池的测试类

 * 

 * @author Justxin

 *

 */

public class DateDemo1 {

@Test

public void demo2() {

// 创建连接池


Connection conn = null;

PreparedStatement pstmt = null;

ResultSet rs = null;

try {

ComboPooledDataSource dataSource = new ComboPooledDataSource();

conn = dataSource.getConnection();

String sql = "SELECT * FROM course";

pstmt = conn.prepareStatement(sql);

rs = pstmt.executeQuery();

while (rs.next()) {

int id = rs.getInt("id");

String name = rs.getString("name");

String category = rs.getString("category");

String desp = rs.getString("desp");

Date createTime = rs.getDate("createTime");

System.out.println(id + " " + name + " " + category + " " + desp + " " + createTime + " ");

}

} catch (Exception e) {

e.printStackTrace();

} finally {

JDBCutils.release(rs, pstmt, conn);

}


}


}

<?xml version="1.0" encoding="UTF-8"?>

<c3p0-config>

<default-config>

<property name="driverClass">com.mysql.cj.jdbc.Driver</property>

<property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbctest?serverTimezone=UTC&amp;characterEncoding=utf8</property>

<property name="user">root</property>

<property name="password">X@angS@erSheng</property>


</default-config>

</c3p0-config>


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学,老师在你的另一个问答下回答你了https://class.imooc.com/course/qadetail/166306 祝学习愉快~

  • 慕桂英3475789 提问者 #1
    搞了半天原来是起文件名的时候直接复制c3p0-config.xml,现在?了
    2019-11-02 16:25:11
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师