java - 在 C# 中使用 getBytes() 从 SQL 中获取数据(提供了 JAVA 代码)

标签 java c#

只是想知道,有谁知道如何在 C# 中使用 getBytes("test")?

我试图解压缩一个用 Java 压缩的结果并保存到数据库中。我已经用 JAVA 编写了代码并设法解压缩并返回结果(在下面找到 JAVA 代码)。不幸的是,我无法在 C# 中做同样的事情。有谁知道如何将我的 JAVA 代码转换为 C#?

/** Generate All Output into One HL7 File **/
public static void generateHL7File(ResultSet rs, String dt, String location)
{
    try {       
        while (rs.next()) {
            String payload= unZIP(rs.getBytes("test"));
        }   
        f.close();  
    } catch ( Exception Ex ) {

    }           
}

/** Unzip string **/
public static String unZIP(byte[] Source) {
    ByteArrayInputStream bins= new ByteArrayInputStream(Source);
    byte[] buf= new byte[2048];
    StringBuffer rString= new StringBuffer("");
    int len;

    try {
        GZIPInputStream zipit= new GZIPInputStream(bins);
        while ((len = zipit.read(buf)) > 0) {
             rString.append(new String(buf).substring(0, len));
        }
        return rString.toString();
    } catch (Exception Ex) {
      return "";
    }
}   

最佳答案

ResultSet在C#中类似的类是SqlDataReader , 它有 GetBytes读取BLOB数据的方法。检查文档中的示例。

JAVA 和 C# 之间的转换不是一件容易的事,另一个想法是使用 Process类来运行您的 JAVA 程序,并从 STDOUT 获取结果。

关于java - 在 C# 中使用 getBytes() 从 SQL 中获取数据(提供了 JAVA 代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54175361/

相关文章:

C# 在使用循环访问内存时比 Java 慢一半?

c# - 使用 Quartz.NET 和简单注入(inject)器进行构造函数注入(inject)

java - 我怎样才能创建一个包含许多相同对象的构造函数,但如果其中一个对象为空则忽略它?

java - 如何在 BIRT API 中设置 Excel 工作表名称?

java - 如何使用 Apache Commons DirectoryWalker?

c# - 从ProgID获取dll目录

c# - 将 App.xaml 设置为 UserControl WPF(以连接定位器)

java - 理解spring bin名称 "&myBean"

java - 尝试调用数组并设置文本文件中的值

c# - 在不同线程中使用mshtml接口(interface)