gpt4 book ai didi

c# - 异常 : No suitable driver found for jdbc:derby:\\serveraddress\db;create=false

转载 作者:搜寻专家 更新时间:2023-10-30 22:37:13 24 4
gpt4 key购买 nike

我知道这个问题已经被问过很多次了……但它总是指的是 JAVA。这次不行

  1. 代码是使用 derbyNET.dll 在 C# 中构建的(并从 .jar 编译为.dll derby.dll 和 derbytools.dll)
  2. 用 Java 编写的相同代码(也使用 javac 在 JAVA 中编译&& java...) 仅当我在程序运行之前添加时才能正常工作:设置CLASSPATH=C:\PROGRA~1\Java\JDK18~1.0_7\DB-DER~1.0-B\lib\derby.jar;C:\PROGRA~1\Java\JDK18~1.0_7\DB-DER~1.0- B\lib\derbytools.jar;
  3. 用 C# 编写的代码抛出上述错误。我也试过改造此代码从 java 到 c#,错误是相同的。
  4. 我很确定这个问题是因为 C# 看不到作为驱动程序的库(derby.dll 和 derbytools.dll)

关于如何将此驱动程序添加到 visual studio 的任何建议?

C# 代码:

try{
DerbyNET derbyDB = new DerbyNET(@"\\serveraddress\sql\db; create=false");
if (!derbyDB.openConnection()){
//Error opening Derby DB
Console.WriteLine("not connected");
return;
}

DataTable oDT = derbyDB.getRS("SELECT * FROM admin.user_data") as DataTable;
if (oDT.Columns[0].ColumnName == "Erro"){
//Read the ** ERRORS ** section below
Thread.Sleep(1000);
oDT = derbyDB.getRS("SELECT * FROM FROM admin.user_data") as DataTable;
}
else if (oDT.Rows.Count == 1 && oDT.Columns.Count == 1){
//Some error occured
String strError = derbyDB.getLastError();
return;
}

foreach (DataRow row in oDT.Rows){
Console.WriteLine("---ROW---");
foreach (var item in row.ItemArray){
Console.Write("Item: ");
Console.WriteLine(item);
}
}
derbyDB.closeConnection();
}
catch (Exception ex){
Console.WriteLine(ex.Message);
}

Java 代码:

try{  
{
con = DriverManager.getConnection("jdbc:derby:\\\\serveraddress\\sql\\db;create=false");
Statement sta = con.createStatement();
ResultSet res = sta.executeQuery("SELECT * FROM ADMIN.USER_DATA");
java.lang.System.@out.println("ADMIN.USER_DATA: ");
while (res.next()){
java.lang.System.@out.println(" " + res.getString("USERID") + ", " + res.getString("PASSWORD") + ", " + res.getString("FIRST_NAME") + ", " + res.getString("LAST_NAME") +
", " + res.getString("EMAIL"));
}
res.close();
sta.close();
con.close();
}
}
catch (System.Exception e){
{
java.lang.System.err.println("Exception: " + e.getMessage());
}
}

最佳答案

我已经解决了这个问题。1) 必须通过 ikvmc 将两个库 derbytools.jar 和 derby.jar 编译为 .dll 并添加为引用2)需要添加NuGet包“IKVM.OpenJDK.Jdbc和IKVM.OpenJDK.Core3) 当前代码是 (C#):

using System;
using System.Diagnostics;
using java.sql;
DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());
Connection derbyConn = DriverManager.getConnection("jdbc:derby:\\\\serveraddress\\directory\\sql\\db;create=false");
Statement sta = derbyConn.createStatement();
ResultSet res = sta.executeQuery("SELECT * FROM tablename");
java.lang.System.@out.println("tablename: ");
while (res.next())
{

java.lang.System.@out.println(" " + res.getString("1stColumn") + ", " + res.getString("2ndColumn"));
}
res.close()
sta.close();
derbyConn.close();

关于c# - 异常 : No suitable driver found for jdbc:derby:\\serveraddress\db;create=false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36580005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com