- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近在 Windows 10 计算机上安装了 jdk 和 jre,但无法让旧计算机上的任何项目运行。主要困难是 jdk1.8.0_60 不包含 JavaDB/Derby,即版本中没有安装“db”目录,而 jdk1.7.0_79 确实有一个 db 文件夹与通常的 bin、include 和lib 目录。该软件包还包含一个名为 derbyDb 的示例数据库。为了纠正这个问题,我从 Apache 网站下载了 derby,然后在 cmd shell 中相应地验证了 derby 和 java:
检查了 Derby 之路:
>C:\Users\Administrator>echo %DERBY_HOME%
(Output) C:\Apache\db-derby-10.14.2.0-bin
检查JDK的路径:
C:\Users\Administrator>echo %JAVA_HOME%
(Output) C:\Program Files\Java\jdk1.8.0_60
将 DERBY_HOME/bin 目录添加到 PATH 环境变量中,并通过系统 > 环境变量对话框进行检查。已验证路径包括:
C:\Program Files\Java\jdk1.8.0_191\bin
C:\Program Files\Java\jre1.8.0_191\bin
检查设置为指向类库的路径:
C:\Users\Administrator>echo %CLASSPATH%
(output) .;C:\Apache\db-derby-10.14.2.0-bin\lib;
由于我从旧 Windows 8.1 机器复制过来的数据库项目都无法正常工作,因此我尝试通过从 C 运行演示应用
下载如下:SimpleApp.java
来了解发生了什么情况:\Apache\db-derby-10.14.2.0-bin\demo\programs\simple
在 cmd shell 中将目录更改为 SimpleApp 的主目录并尝试运行该应用程序:
C:\Apache\db-derby-10.14.2.0-bin\demo\programs\simple>java SimpleApp
输出:
SimpleApp starting in embedded mode
----- SQLException -----
SQL State: 08001
Error Code: 0
Message: No suitable driver found for jdbc:derby:derbyDB;create=true
SimpleApp finished
我根本不明白发生了什么或从哪里开始解决此问题,并且确实需要一些帮助。这是 SimpleApp 源代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;
/**
* <p>
* This sample program is a minimal Java application showing JDBC access to a
* Derby database.</p>
* <p>
* Instructions for how to run this program are
* given in <A HREF=example.html>example.html</A>, by default located in the
* same directory as this source file ($DERBY_HOME/demo/programs/simple /).</p>
* <p>
* Derby applications can run against Derby running in an embedded
* or a client/server framework.</p>
* <p>
* When Derby runs in an embedded framework, the JDBC application and Derby
* run in the same Java Virtual Machine (JVM). The application
* starts up the Derby engine.</p>
* <p>
* When Derby runs in a client/server framework, the application runs in a
* different JVM from Derby. The connectivity framework (in this case the Derby
* Network Server) provides network connections. The client driver is loaded
* automatically.</p>
*/
public class SimpleApp
{
/* the default framework is embedded */
private String framework = "embedded";
private String protocol = "jdbc:derby:";
/**
* <p>
* Starts the demo by creating a new instance of this class and running
* the <code>go()</code> method.</p>
* <p>
* When you run this application, you may give one of the following
* arguments:
* <ul>
<li><code>embedded</code> - default, if none specified. Will use
* Derby's embedded driver. This driver is included in the derby.jar
* file.</li>
* <li><code>derbyclient</code> - will use the Derby client driver to
* access the Derby Network Server. This driver is included in the
* derbyclient.jar file.</li>
* </ul>
* <p>
* When you are using a client/server framework, the network server must
* already be running when trying to obtain client connections to Derby.
* This demo program will will try to connect to a network server on this
* host (the localhost), see the <code>protocol</code> instance variable.
* </p>
* <p>
* When running this demo, you must include the correct driver in the
* classpath of the JVM. See <a href="example.html">example.html</a> for
* details.
* </p>
* @param args This program accepts one optional argument specifying which
* connection framework (JDBC driver) to use (see above). The default
* is to use the embedded JDBC driver.
*/
public static void main(String[] args)
{
new SimpleApp().go(args);
System.out.println("SimpleApp finished");
}
/**
* <p>
* Starts the actual demo activities. This includes creating a database by
* making a connection to Derby (automatically loading the driver),
* creating a table in the database, and inserting, updating and retrieving
* some data. Some of the retrieved data is then verified (compared) against
* the expected results. Finally, the table is deleted and, if the embedded
* framework is used, the database is shut down.</p>
* <p>
* Generally, when using a client/server framework, other clients may be
* (or want to be) connected to the database, so you should be careful about
* doing shutdown unless you know that no one else needs to access the
* database until it is rebooted. That is why this demo will not shut down
* the database unless it is running Derby embedded.</p>
*
* @param args - Optional argument specifying which framework or JDBC driver
* to use to connect to Derby. Default is the embedded framework,
* see the <code>main()</code> method for details.
* @see #main(String[])
*/
void go(String[] args)
{
/* parse the arguments to determine which framework is desired*/
parseArguments(args);
System.out.println("SimpleApp starting in " + framework + " mode");
/* We will be using Statement and PreparedStatement objects for
* executing SQL. These objects, as well as Connections and ResultSets,
* are resources that should be released explicitly after use, hence
* the try-catch-finally pattern used below.
* We are storing the Statement and Prepared statement object references
* in an array list for convenience.
*/
Connection conn = null;
ArrayList<Statement> statements = new ArrayList<Statement>(); // list of Statements, PreparedStatements
PreparedStatement psInsert;
PreparedStatement psUpdate;
Statement s;
ResultSet rs = null;
try
{
Properties props = new Properties(); // connection properties
// providing a user name and password is optional in the embedded
// and derbyclient frameworks
props.put("user", "user1");
props.put("password", "user1");
/* By default, the schema APP will be used when no username is
* provided.
* Otherwise, the schema name is the same as the user name (in this
* case "user1" or USER1.)
*
* Note that user authentication is off by default, meaning that any
* user can connect to your database using any password. To enable
* authentication, see the Derby Developer's Guide.
*/
String dbName = "derbyDB"; // the name of the database
/*
* This connection specifies create=true in the connection URL to
* cause the database to be created when connecting for the first
* time. To remove the database, remove the directory derbyDB (the
* same as the database name) and its contents.
*
* The directory derbyDB will be created under the directory that
* the system property derby.system.home points to, or the current
* directory (user.dir) if derby.system.home is not set.
*/
conn = DriverManager.getConnection(protocol + dbName
+ ";create=true", props);
System.out.println("Connected to and created database " + dbName);
// We want to control transactions manually. Autocommit is on by
// default in JDBC.
conn.setAutoCommit(false);
/* Creating a statement object that we can use for running various
* SQL statements commands against the database.*/
s = conn.createStatement();
statements.add(s);
// We create a table...
s.execute("create table location(num int, addr varchar(40))");
System.out.println("Created table location");
// and add a few rows...
/* It is recommended to use PreparedStatements when you are
* repeating execution of an SQL statement. PreparedStatements also
* allows you to parameterize variables. By using PreparedStatements
* you may increase performance (because the Derby engine does not
* have to recompile the SQL statement each time it is executed) and
* improve security (because of Java type checking).
*/
// parameter 1 is num (int), parameter 2 is addr (varchar)
psInsert = conn.prepareStatement(
"insert into location values (?, ?)");
statements.add(psInsert);
psInsert.setInt(1, 1956);
psInsert.setString(2, "Webster St.");
psInsert.executeUpdate();
System.out.println("Inserted 1956 Webster");
psInsert.setInt(1, 1910);
psInsert.setString(2, "Union St.");
psInsert.executeUpdate();
System.out.println("Inserted 1910 Union");
// Let's update some rows as well...
// parameter 1 and 3 are num (int), parameter 2 is addr (varchar)
psUpdate = conn.prepareStatement(
"update location set num=?, addr=? where num=?");
statements.add(psUpdate);
psUpdate.setInt(1, 180);
psUpdate.setString(2, "Grand Ave.");
psUpdate.setInt(3, 1956);
psUpdate.executeUpdate();
System.out.println("Updated 1956 Webster to 180 Grand");
psUpdate.setInt(1, 300);
psUpdate.setString(2, "Lakeshore Ave.");
psUpdate.setInt(3, 180);
psUpdate.executeUpdate();
System.out.println("Updated 180 Grand to 300 Lakeshore");
/*
We select the rows and verify the results.
*/
rs = s.executeQuery(
"SELECT num, addr FROM location ORDER BY num");
/* we expect the first returned column to be an integer (num),
* and second to be a String (addr). Rows are sorted by street
* number (num).
*
* Normally, it is best to use a pattern of
* while(rs.next()) {
* // do something with the result set
* }
* to process all returned rows, but we are only expecting two rows
* this time, and want the verification code to be easy to
* comprehend, so we use a different pattern.
*/
int number; // street number retrieved from the database
boolean failure = false;
if (!rs.next())
{
failure = true;
reportFailure("No rows in ResultSet");
}
if ((number = rs.getInt(1)) != 300)
{
failure = true;
reportFailure(
"Wrong row returned, expected num=300, got " + number);
}
if (!rs.next())
{
failure = true;
reportFailure("Too few rows");
}
if ((number = rs.getInt(1)) != 1910)
{
failure = true;
reportFailure(
"Wrong row returned, expected num=1910, got " + number);
}
if (rs.next())
{
failure = true;
reportFailure("Too many rows");
}
if (!failure) {
System.out.println("Verified the rows");
}
// delete the table
s.execute("drop table location");
System.out.println("Dropped table location");
/*
We commit the transaction. Any changes will be persisted to
the database now.
*/
conn.commit();
System.out.println("Committed the transaction");
/*
* In embedded mode, an application should shut down the database.
* If the application fails to shut down the database,
* Derby will not perform a checkpoint when the JVM shuts down.
* This means that it will take longer to boot (connect to) the
* database the next time, because Derby needs to perform a recovery
* operation.
*
* It is also possible to shut down the Derby system/engine, which
* automatically shuts down all booted databases.
*
* Explicitly shutting down the database or the Derby engine with
* the connection URL is preferred. This style of shutdown will
* always throw an SQLException.
*
* Not shutting down when in a client environment, see method
* Javadoc.
*/
if (framework.equals("embedded"))
{
try
{
// the shutdown=true attribute shuts down Derby
DriverManager.getConnection("jdbc:derby:;shutdown=true");
// To shut down a specific database only, but keep the
// engine running (for example for connecting to other
// databases), specify a database in the connection URL:
//DriverManager.getConnection("jdbc:derby:" + dbName + ";shutdown=true");
}
catch (SQLException se)
{
if (( (se.getErrorCode() == 50000)
&& ("XJ015".equals(se.getSQLState()) ))) {
// we got the expected exception
System.out.println("Derby shut down normally");
// Note that for single database shutdown, the expected
// SQL state is "08006", and the error code is 45000.
} else {
// if the error code or SQLState is different, we have
// an unexpected exception (shutdown failed)
System.err.println("Derby did not shut down normally");
printSQLException(se);
}
}
}
}
catch (SQLException sqle)
{
printSQLException(sqle);
} finally {
// release all open resources to avoid unnecessary memory usage
// ResultSet
try {
if (rs != null) {
rs.close();
rs = null;
}
} catch (SQLException sqle) {
printSQLException(sqle);
}
// Statements and PreparedStatements
int i = 0;
while (!statements.isEmpty()) {
// PreparedStatement extend Statement
Statement st = (Statement)statements.remove(i);
try {
if (st != null) {
st.close();
st = null;
}
} catch (SQLException sqle) {
printSQLException(sqle);
}
}
//Connection
try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException sqle) {
printSQLException(sqle);
}
}
}
/**
* Reports a data verification failure to System.err with the given message.
*
* @param message A message describing what failed.
*/
private void reportFailure(String message) {
System.err.println("\nData verification failed:");
System.err.println('\t' + message);
}
/**
* Prints details of an SQLException chain to <code>System.err</code>.
* Details included are SQL State, Error code, Exception message.
*
* @param e the SQLException from which to print details.
*/
public static void printSQLException(SQLException e)
{
// Unwraps the entire exception chain to unveil the real cause of the
// Exception.
while (e != null)
{
System.err.println("\n----- SQLException -----");
System.err.println(" SQL State: " + e.getSQLState());
System.err.println(" Error Code: " + e.getErrorCode());
System.err.println(" Message: " + e.getMessage());
// for stack traces, refer to derby.log or uncomment this:
//e.printStackTrace(System.err);
e = e.getNextException();
}
}
/**
* Parses the arguments given and sets the values of this class's instance
* variables accordingly - that is, which framework to use, the name of the
* JDBC driver class, and which connection protocol to use. The
* protocol should be used as part of the JDBC URL when connecting to Derby.
* <p>
* If the argument is "embedded" or invalid, this method will not change
* anything, meaning that the default values will be used.</p>
* <p>
* @param args JDBC connection framework, either "embedded" or "derbyclient".
* Only the first argument will be considered, the rest will be ignored.
*/
private void parseArguments(String[] args)
{
if (args.length > 0) {
if (args[0].equalsIgnoreCase("derbyclient"))
{
framework = "derbyclient";
protocol = "jdbc:derby://localhost:1527/";
}
}
}
}
最佳答案
Checked the path set to point to class libraries:
C:\Users\Administrator>echo %CLASSPATH%
(output) .;C:\Apache\db-derby-10.14.2.0-bin\lib;
这实际上并不像您想象的那样工作。命名目录不包含该目录中的所有 jar 文件。
您需要为类路径中的每个 jar 文件命名;或者,我所做的是使用“derbyrun.jar”jar 文件,它是一个伞式 jar,自动包含所有其他 Derby jar 文件。
因此,将您的CLASSPATH
设置为C:\Apache\db-derby-10.14.2.0-bin\lib\derbyrun.jar
关于java - 为什么找不到合适的jdbc驱动:derby:derbyDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53350318/
Select distinct APP.bca_cart.InventoryCode,APP.bca_cart.InventoryID,APP.bca_cart.CartID,APP.bca_cart
有没有办法在 derby 数据库中像 mysql 那样逐列添加? 最佳答案 我不相信。列排序并不是真正的标准 SQL 功能。编写良好的数据库应用程序不应该关心列排序。您可以通过命名 SQL 语句中的列
我已经在 Glassfish/Netbeans 中设置了 Derby DB 密码。我还选中了记住我复选框。 现在我不能再更改密码了。 最佳答案 要更改密码,您只需执行: call SYSCS_UTIL
我在 google 上搜索了一些关于 apache derby 中不区分大小写的搜索。所有谷歌搜索结果都非常旧(2007 年最新)。我发现在不丢失索引的情况下搜索不区分大小写是不可能的(“LOWER”
如何做到这一点? SYSCOLUMNS 系统表只有表的列。 SYSCHECKS 有一个 REFERENCEDCOLUMNS 对象。有什么办法可以得到这个。 我知道 JDBC getPrimaryKey
我已经使用derby db开发了一个应用程序。我已经在系统中创建了数据库。我需要将应用程序与数据库一起交付。我已删除表中的所有数据。仅保留表(数据为空的结构)。因此,如果我将db文件(所有这些文件,l
Derby没有rownum功能吗? 在oracle中,我可以选择前3行,如下所示。 select * from a where rownum < 3 在here中,他们建议如下。但这很乏味。 SELE
我正在使用嵌入式 Java 数据库来保存公交时刻表。当新计划可用时,我会自动将新计划加载到数据库表中,然后从数据库中删除旧计划。这会自动发生,无需用户干预。 我注意到数据库会随着时间的推移而变慢。我有
假设我已连接到 derby 服务器。我需要知道哪些数据库可供我连接。有命令可以这样做吗? 最佳答案 没有这样的命令。 Derby 不维护所有已知数据库的整体注册表或目录。 每个数据库都是独立的,可以通
我正在关注 Derby.js getting started guide .我跑了 $ npm install -g derby 一切都成功了,但是当我输入 $ derby new app-name
我正在寻找如何检查数据库是否存在的信息——从 Java 代码——在 hsqldb 和 Apache derby 中。在Mysql中很容易,因为我可以查询系统表--INFORMATION_SCHEMA.
我在我的 Mac 上使用 Netbeans 7.1 创建了一个 JavaDB(Derby) 数据库,我正在搜索一个免费软件应用程序,我可以使用它来查看包含所有表及其连接的完整数据库模式的图片。有任何想
我想在网络服务器模式下使用 Derby,并按照他们网站上的说明进行操作。 Derby 开局: /opt/glassfish/4.0/javadb/bin/NetworkServerControl st
我有一个使用 derby 和 JPA 的项目。我可以在我的应用程序中正常连接到数据库。我想使用 SQL Developer 连接到嵌入式数据库,以便我可以轻松浏览/查询数据库中的数据。 这是我正在使用
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 8年前关闭。 Improve this questi
有没有办法在 ij 中“漂亮地打印”查询结果?由于在查询结果中到处乱扔列,因此默认结果看起来非常难以理解。 在 PostgreSQL 中,有/pset 命令来控制 pgsql 命令的结果,我正在为 D
当我在 WildFly 上正常定义 Derby 数据源时,db.lck 文件未被删除,这表明每次关闭 WildFly 时数据库都没有正确关闭。因为嵌入式 Derby 需要一个特殊的关闭过程,该过程正在
我在 Google 上没有找到任何相关信息,但我认为这一定是可能的。 我的 Hibernate 项目遇到了一个严重的问题: 我有两个模块,一个主模块和一个工具模块。他们应该使用相同的数据库(嵌入式 D
我正在使用 Spring 构建一个 JavaEE 应用程序,我正在尝试将它与 DerbyEmbeddedDriver 连接起来。该应用程序将在 SAP Hana Cloud Platform 试用版上
我正在使用 Derby DB作为我的 Qpid broker 的存储.当作为嵌入式数据库运行时,试图找出 Derby 存储数据文件的位置。 任何人都知道文件所在的位置或如何设置要使用的目录? 最佳答案
我是一名优秀的程序员,十分优秀!