Code Monkey home page Code Monkey logo

chaolib's People

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

lujincheng1

chaolib's Issues

你好,我是一个java web初学者,有问题想请教您~

我最近在做java web的项目,觉得您的项目写的很好,想借鉴学习一下,但是我的数据库jdbc驱动一直报错。我首先添加了我的jar包在类目录下,然后添加进build path里,但是我用的是您写的第二种连接方法,它一直在报错,您知道是什么原因吗?是我的驱动有问题吗?
我把DBConection.java改成了如下形式:

package com.choyri.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 * 数据库连接
 */
public class DBConnection {

    private Connection conn = null;

  /*  
// 数据库连接池
    public DBConnection() {
        DataSource ds = null;
        try {
            ds = (DataSource) (new InitialContext()).lookup("java:comp/env/jdbc/mariadb");
        } catch (NamingException e) {
            e.printStackTrace();
        }
        try {
            conn = ds.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }*/

    // 传统连接
    public DBConnection() {
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/chaolib", "root", "root");
        } catch (SQLException e) {
           e.printStackTrace();
        }
   }

    public Connection getConnection() {
        return conn;
    }

    public void close() {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

它报的错是
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/chaolib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.