“组合不兼容的数据类型”错误与日期值上的查询

时间:2017-05-14 08:33:03

标签: java swing ms-access jdbc ucanaccess

我整个程序的目的是从Access数据库中获取值并在jtable中显示特定日期。 我在访问数据库中有一个表,其中for_date字段存储为日期/时间字段,格式为短日期(dd-MM-yyyy)。现在我的程序要求我从数据库中检索特定日期的行。我使用SimpleDateFormat将其转换为访问数据库的格式,但它给出了错误。我得到的错误是: - net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 3.0.4组合不兼容的数据类型。如果使用算术加上将表示时间单位的整数直接添加到日期时间值,则可能发生此异常操作员但没有指定日期单位。在这种特殊情况下,你必须使用,例如,+ 1天

我的代码如下: -

 String table_sel = "ISGS_table";
 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 String date1 = sdf.format(report_date.getDate());
try{
String sql = "Select reporting_date as REPORTING_DATE,for_date as FOR_DATE,outage_date as OUTAGE_DATE,outage_time as OUTAGE_TIME,stat_detail as STATION_DETAILS,res_date as RESTORATION_DATE,rest_time as RESTORATION_TIME,rest_reason as RESTORATION_REASON from " + table_sel+" where for_date='" + date1 + "'";
Connection con = null;
            Statement st = null;
            ResultSet rs = null;
            PreparedStatement pst = null;
            String dbURL = "jdbc:ucanaccess://C:\\Users\\Dell_PC\\Documents\\SYSTEM_OUTAGE_REPORT.accdb";
            con = DriverManager.getConnection(dbURL);
            st = con.createStatement();
            pst = con.prepareStatement(sql);
            rs = pst.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
  con.close();   
       } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }

1 个答案:

答案 0 :(得分:0)

您收到该错误消息是因为您将<!DOCTYPE html> <html ng-app="app" ng-controller="ctrl"> <head> <title></title> <meta charset="utf-8" /> </head> <body> <form name="userFormOne" novalidate> <table> <tr class="form-group" ng-repeat="x in names"> <td> <label>{{ x.field }}</label> </td> <td ng-if="x.type != 'select'"> <input type="{{x.type}}" min="{{x.min}}" max="{{x.max}}" ng-model="x.value" name="{{x.name}}" placeholder="{{x.placeholder}}" ng-required="true"> {{x.value}} </td> <td ng-if="x.type == 'select'"> <select ng-model="x.value" name="{{x.name}}" ng-options="item as item.name for item in x.options"> </select> {{x.value}} </td> </tr> </table> <button ng-disabled="userFormOne.$invalid" ng-click="sendMe()">sendMe</button> </form> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> </body> </html>的值作为字符串文字传递。 UCanAccess遵循使用散列标记(import pandas as pd import matplotlib.pyplot as plt import matplotlib.lines as mlines import matplotlib.animation as anim ... time = df.monat.unique() fig = plt.figure() i = 1 def update(i): plt.clf() dft = df[(df.monat == time[i]) & (df.xcol < 4000)] plt.scatter(x=dft['xcol'], y=dft['ycol'], s=dft['scol'] / 25, c=dft['clr'], linewidth=0, alpha=0.8) plt.title('Title ' + str(time[i]), fontsize=10) plt.xlabel('x label', fontsize=9) plt.ylabel('y label', fontsize=9) plt.xlim(0, 900) # fixed dimensions x plt.ylim(-5, 100) # fixed dimensions y legend1_line2d = list() for val in clrdict.values(): legend1_line2d.append(mlines.Line2D([0], [0], linestyle='none', marker='o', alpha=0.6, markersize=6, markeredgecolor=None, markeredgewidth=0, markerfacecolor=val)) legend1 = plt.legend(legend1_line2d, names, frameon=False, numpoints=1, fontsize=8, loc='upper right') i += 1 ani = anim.FuncAnimation(fig, update, frames=len(time), interval=500) # plt.show() # this will show the ani over and over ani.save("test.mp4", dpi=200, fps=1, codec="libx264", bitrate=5000, extra_args=['-pix_fmt', 'yuv420p']) )作为日期/时间文字分隔符的Access SQL约定。

因此,这会因您引用的错误而失败

for_date

然而这将起作用

#

请注意,如果您使用... WHERE for_date = '2017-02-03'

,它将被视为更好的形式
... WHERE for_date = #2017-02-03#

并使用PreparedStatement传递日期值。