作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我知道这个问题已经被问过很多次了……但它总是指的是 JAVA。这次不行
关于如何将此驱动程序添加到 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/
我是一名优秀的程序员,十分优秀!