jakarta-ee - 无法在 Web Logic derby 数据源上执行语句
问题描述
我正在使用 WebLogic Server 访问数据库。我已通过管理控制台将数据库添加到我的 WebLogic Server 实例中。这是一个 apache derby 数据库。我能够在我的代码中建立连接,但是每次我尝试执行语句时都会出现异常:
java.sql.SQLSyntaxErrorException:架构 'WEBLOGIC' 不存在于 org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(未知来源)
和别人聊天的时候,听说可能我的derby版本老了,不过我刚下载了最新的版本(10.14.2.0)。我还注意到 WLS 有它自己的 derby 目录 (Oracle_Home\wlserver\common\derby),所以我尝试用最新版本替换那里的 lib 文件夹,但这没有任何帮助。
当我尝试执行我的语句时,我的 InsertStudents 方法中发生了异常。我完全迷失在这里。
public class JNDIPrinter {
private static String tableName = "student";
// jdbc Connection
private static Connection conn = null;
private static Statement stmt = null;
public void AddStudents() {
Context ctx = null;
try {
conn = GetConnection();
List<Student> students;
students = new ArrayList<Student>(
Arrays.asList(new Student("first1", "last1", "111-11-1111", "1@1.com", "111 1st st", "user1", "pw1"),
new Student("first2", "last2", "222-22-2222", "2@2.com", "222 2nd st", "user2", "pw2"),
new Student("first3", "last3", "333-33-3333", "3@3.com", "333 3rd st", "user3", "pw3")));
InsertStudents(students);
} catch (Exception e) {
System.out.println(e.toString());
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (NamingException e) {
System.out.println("Failed to close context due to: " + e);
}
}
}
}
private Connection GetConnection() throws NamingException, SQLException {
Context ctx = null;
String url = null;
System.out.println(url);
Hashtable env = new Hashtable();
// This *required* property specifies the factory to be used
// to create the context.
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
if (url != null) {
// This property specifies the URL of the WebLogic Server that will
// provide the naming service. Defaults to t3://localhost:7001
env.put(Context.PROVIDER_URL, url);
}
ctx = new InitialContext(env);
System.out.println("Initial context created");
DataSource ds = (javax.sql.DataSource) ctx.lookup("jhuDataSource");
System.out.println("Datasource created");
java.sql.Connection connection = (java.sql.Connection) ds.getConnection();
return connection;
}
private void InsertStudents(List<Student> students) throws SQLException{
try {
for (Student student : students) {
stmt = conn.createStatement();
stmt.execute("insert into " + tableName + " values ('"
+ student.first_name + "','"
+ student.last_name + "','"
+ student.ssn + "','"
+ student.email + "','"
+ student.address + "','"
+ student.userID + "','"
+ student.password + "')");
stmt.close();
}
} catch (SQLException sqlExcept) {
sqlExcept.printStackTrace();
}
}
}
```````
解决方案
推荐阅读
- scikit-learn - 在 julia 上使用 sklearn.mixture.GaussianMixture 方法
- php - 最终用户尚未完成身份验证和身份验证登录流程 eBay
- kubernetes - 哪个是详细了解 Kubernetes 中 client-go repo 重构的最佳文档
- rxjs - 使用单一模型在多个组件之间传递数据并保存它?
- javascript - Ionic viewchild 变量在 ng-switch 中不可用
- c# - Entity Framework Core:Fluent api 多对多
- javascript - Web 套接字在 javascript 中不能与 SSL 和 WSS 一起使用
- javascript - 使用 Javascript 读取本地 JSON 文件
- c - memcpy重写不起作用
- linux - 如何使用awk,sed在两个特定单词之间打印文本?