繁体   English   中英

.exe的mssql jdbc连接不起作用

[英]mssql jdbc connection for .exe not working

因此,我遇到了这样的情况:我在IDE中编译代码,并且可以正常工作,当我以.jar运行它时,它可以按预期工作,但是当我创建.exe安装程序并将其安装在同一系统上时,应用程序会在尝试className之前停止在下面的代码中

class GenerateImage {

private ResultSet rs;
private List<Row> rowData;
private Row r2;
Connection con;
private static final Shape circle = new Ellipse2D.Double(-3, -3, 6, 6);

public GenerateImage() throws IOException, SQLException, ParseException {
    JOptionPane.showMessageDialog(null, "Inside");
    Date startDate, endDate, currentDate, currentTime;
    String date = "2018-07-29 00:00:00";
    float minValue = 0;
    float maxValue = 0;
    String date_field = "CurDT";
    String chartFilePath = "E:\\TrendChart.jpeg";
    String pdfFilePath = "E:\\" + date.replaceAll(":", "_").replaceAll("-", "_") + "_TREND_report.pdf";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
    String url = "jdbc:sqlserver://DESKTOP-DINSO\\DINSO:1433;databaseName=master;integratedSecurity=true";
    JOptionPane.showMessageDialog(null, "step 1");

    try {
        JOptionPane.showMessageDialog(null, Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"));
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        JOptionPane.showMessageDialog(null, Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"));
    } catch (ClassNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "class not found");
        Logger.getLogger(GenerateImage.class.getName()).log(Level.SEVERE, null, ex);
    }
    //JOptionPane.showMessageDialog(null, DriverManager.getConnection(url));
    con = DriverManager.getConnection(url);
    if (con == null) {
        JOptionPane.showMessageDialog(null, "connection is null");
    } else {
        JOptionPane.showMessageDialog(null, "connection is not null");
    }
    TimeSeries value = new TimeSeries("value");

    JOptionPane.showMessageDialog(null, "try started");
    String sql;
     //            sql = "SELECT * FROM \"Sheet1$\" WHERE " + date_field + 
     ">=" + startdate + " AND " + date_field + "<= " + enddate;
    sql = "SELECT * FROM \"Sheet1\"";
    Statement stmt = con.createStatement();
    int count = 0;
    ResultSet rs1 = stmt.executeQuery("SELECT COUNT(*) FROM \"Sheet1\"");
    while (rs1.next()) {
        count = rs1.getInt(1);
    }
    rs = stmt.executeQuery(sql);
    if (rs == null) {
        JOptionPane.showMessageDialog(null, "rs is null");
    }
    int sizeofRS = rs.getRow();

    rowData = new ArrayList<Row>();

    int i = 0;
    System.out.println("size of rs is " + count);

    for (int j = 0; j < count; j = j + 1) {
        if (j < count) {
            rs.next();
            r2 = new Row(rs.getString(1), rs.getString(5));
            rowData.add(r2);
            currentDate = sdf.parse(rs.getString(1));
            value.addOrUpdate(new Minute(currentDate), 
            Float.valueOf(rs.getString(5)));
            System.out.println(" row data size " + rowData.size());
        }
    }
    con.close();
    JOptionPane.showMessageDialog(null, "sql connection closed");
    System.out.println("Connection closed");
}

我还在项目配置中包括了sqljdbc.dll目录。

我添加了许多弹出窗口,仅用于调试目的。

在主方法中调用此GenerateImage构造函数。

我的数据库类型是odbc。

该代码在IDE和jar格式中均能正常工作。 当打包为.exe并安装在同一系统上时,为什么这不起作用。

我使用了NetBeans的Inno本机软件包管理器。

好的,这是我意识到的一个关键问题。 问题是jre中缺少文件“ sqljdbc_auth.dll”。 因此,打包应用程序时,请记住将文件复制到jre目录中,以便将其包含在包中。

在另一种情况下,您已正确完成了所有操作,但应用程序也无法正常运行,因为客户端计算机已经安装了jre,不会丢失文件。 因此,在这里您将不得不再次复制文件或要求客户端从系统中删除任何jre或jdk,因为应用程序将首先使用系统jre,然后更喜欢打包的jre

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM