问题描述
我正在使用 java 和 derby 数据库.我在 netbeans IDE 中构建了 derby 数据库.我使用 clean 和 build 选项创建了一个可执行的 jar 文件.
I am using java and derby database. I built derby database in netbeans IDE. I have created a executable jar file using clean and build option.
在 netbeans 中运行项目时,它可以很好地连接到数据库.但是如果我运行可执行的 jar 文件,它不会连接到数据库.
While running the project in netbeans, it connect to database goodly. But if I run executable jar file, it doesn't connect to the database.
帮我用derby数据库创建一个可执行的jar文件,它应该可以在任何其他系统上运行.连接数据库的部分编码是
Help me to create a executable jar file with derby database, It should run on any other system.Part of coding to connect database is
String str = textarea.getText();
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
String stm="select url from pingatabl where functn=?";
PreparedStatement st = conn.prepareStatement(stm);
st.setString(1, str);
//Excuting Query
ResultSet rs = st.executeQuery();
if (rs.next()) {
String s = rs.getString(1);
//Sets Records in frame
JFrame fm = new JFrame();
fm.setVisible(true);
fm.setSize(500,750);
JEditorPane jm = new JEditorPane();
fm.add(jm);
jm.setPage(ClassLoader.getSystemResource(s));
推荐答案
你和 2 年前一样是新手.问题是您根本没有安装 derby.看,Derby 是一个数据库服务器,而 netbeans 有它自己的 derby 版本.因此,它在 Netbeans 中运行时运行,但在从可执行文件运行时不启动.因此,首先,从 https://db.apache.org/derby/ 安装 derby,然后启动服务器,然后您可以从可执行文件访问它.另外,我建议您使用 MySQL
服务器而不是 derby.但是,您始终可以使用 derby.
You are as novice as I was 2 years ago. The thing is that you have not installed derby at all. See, Derby is a database server and netbeans has its own version of derby. So, it runs when made to run inside Netbeans but does not start when run from an executable file. So, first, install derby from https://db.apache.org/derby/ and then start the server and then you can access it from the executable file. Also, I would recommend you to use MySQL
server instead of derby. But, you can always use derby.
这篇关于如何从可执行 jar 文件访问 derby 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!