h2数据库驱动程序发出驱动程序未找到消息

时间:2016-10-18 08:25:52

标签: java eclipse jdbc h2

我已经学习了几天的JDBC连接,并且最近使用h2关系数据库尝试了这段代码。我收到一条消息,因为驱动程序不可用,我已经检查过,驱动程序在那里它应该在lib中 eclipse包的文件夹。我该怎么办?

if (!isset($_SESSION['usr_id'])) {
    header("Location: login.php");
}

2 个答案:

答案 0 :(得分:1)

//declaring host ,username and password 
    String host="jdbc:h2:tcp://localhost/~/test/INFORMATION_SCHEMA.COLLATIONS";
    String uName="sa";
    String uPass="sa";

    //giving a connection to the h2 database driver driver 
    Connection conn = DriverManager.getConnection("h2","sa","sa");

改变如:

//declaring host ,username and password 
    String host="jdbc:h2:tcp://localhost/~/test/INFORMATION_SCHEMA.COLLATIONS";
    String uName="sa";
    String uPass="sa";

    //giving a connection to the h2 database driver driver 
    Connection conn = DriverManager.getConnection(host,uName,uPass);

并确保 h2.jar 必须包含在您的类路径中

如果想要下载检查:

http://www.java2s.com/Code/Jar/h/Downloadh2jar.htm

答案 1 :(得分:-2)

使用此代码

使用您的数据库名称和所有

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

    public class OracleJDBC {

        public static void main(String[] argv) {

            System.out.println("-------- Oracle JDBC Connection Testing ------");

            try {

                Class.forName("oracle.jdbc.driver.OracleDriver");

            } catch (ClassNotFoundException e) {

                System.out.println("Where is your Oracle JDBC Driver?");
                e.printStackTrace();
                return;

            }

            System.out.println("Oracle JDBC Driver Registered!");

            Connection connection = null;

            try {

                connection = DriverManager.getConnection(
                        "jdbc:oracle:thin:@localhost:1521:xe","system","murali123");

            } catch (SQLException e) {

                System.out.println("Connection Failed! Check output console");
                e.printStackTrace();
                return;

            }

            if (connection != null) {
                System.out.println("You made it, take control your database now!");
            } else {
                System.out.println("Failed to make connection!");
            }
        }

    }

在这里你会知道问题出在哪里。试试这个告诉我你得到的输出。