“找不到合适的司机”从JAR运行时 [英] "No suitable driver found" when running from JAR

查看:89
本文介绍了“找不到合适的司机”从JAR运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一款小游戏,其中用户输入的文本需要在MS Access数据库中发布。

I have developed a small game in which the text input by the user needs to be posted in a MS Access Database.

这一切在NetBeans中运行良好但每当我从JAR文件访问它时(这最终是我需要传递给我的客户端),它不会发布任何内容数据库。实际上它返回以下错误:

It all works fine in NetBeans but whenever I access it from the JAR file (which is ultimately what I need to hand to my client), it does not post anything to the database. In fact it returns the following error:

java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C:\Users\Paul\Desktop\Spelli\RispostiDB.mdb

这是相关代码:

public void postAnsDB()
    {
       String tableName = "Form"+studentGroup +"_"+studentSurname+"_"+studentName+"";

       answerModifier();

       try{

                String strurl="jdbc:ucanaccess://C:\\Users\\Paul\\Desktop\\Spelli\\RispostiDB.mdb";
                Connection conn=DriverManager.getConnection(strurl, "", "");
                Statement stmt=conn.createStatement();

                //Post Student Details to DB 

                String post = "INSERT INTO "+tableName+"(ID, responses, Correct_Response, Valid_Invalid, Marks) VALUES ('"+ansID+"', '"+answer+"', '"+correct+"', '"+valid+"', '"+marks+"');";

                stmt.executeUpdate(post);
            }
        catch(Exception e)
        {
            System.out.println("Exception found in postAnsDB: "+e);
        }
    }


推荐答案

您在NetBeans中构建项目,它在项目的主文件夹中创建一个 dist 文件夹,将代码的JAR文件放在该文件夹中,并放置依赖项(JAR)所需组件(如UCanAccess,Jackcess,HSQLDB和Apache Commons位)的文件到名为 lib 的子文件夹中。您需要确保将 lib 文件夹复制到目标计算机并放在与主JAR文件相同的文件夹中。有关详细信息,请参见此处

When you build your project in NetBeans it creates a dist folder in the home folder of your project, puts the JAR file for your code in that folder, and also puts the dependencies (JAR files for required components like UCanAccess, Jackcess, HSQLDB, and Apache Commons bits) into a subfolder named lib. You need to ensure that the lib folder gets copied to the target machine and placed in the same folder as your main JAR file. Look here for details.

这篇关于“找不到合适的司机”从JAR运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆