在将数据插入Excel时获取异常

时间:2014-04-01 13:29:17

标签: java jsp jdbc odbc export-to-excel

我有以下HTML文件。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        div.ui-datepicker{
 font-size:10px;
}
    </style>
        <link rel="stylesheet" href="jquery-ui-1.10.4.custom/development-bundle/themes/base/jquery.ui.all.css">
    <script src="jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js"></script>
    <script src="jquery-ui-1.10.4.custom/development-bundle/ui/jquery.ui.core.js"></script>
    <script src="jquery-ui-1.10.4.custom/development-bundle/ui/jquery.ui.widget.js"></script>
    <script src="jquery-ui-1.10.4.custom/development-bundle/ui/jquery.ui.datepicker.js"></script>
    <link rel="stylesheet" href="../jquery-ui-1.10.4.custom/development-bundle/demos.css">

</head>
<body>
<form method="post" action="ToExcel.jsp">
    <div>
        <table class="auto-style1">
            <tr>
                <td>Comments</td>
                <td><input type="text" name="comments" id="comments"></td>
                <td colspan="2">No. of lines updated in PSIS</td>
                <td colspan="2"><input type="text" name="updatedl" id="updatedl"></td>
            </tr>
            <tr>
                <td>Shipment ID</td>
                <td><input type="text" name="sid" id="sid"></td>
                <td>SAP TXT Description</td>
                <td><input type="text" name="desc" id="desc"></td>
                <td>Phoenix Pub Code</td>
                <td><input type="text" name="pubcode" id="pubcode"></td>
            </tr>
            <tr>
                <td>Product Type</td>
                <td><select name="Type" id="Type">
                  <option value="" disabled selected>Select your option</option>
                  <option value="Looseleaf - Update">Looseleaf - Update</option>
                  <option value="Pamphlet">Pamphlet</option>
                </select></td>
                <td colspan="2">Status of the job</td>
                <td colspan="2"><select name="status" id="status">
                <option value="" disabled selected>Select your option</option>
<option value="Assigned">Assigned</option>
<option value="Completed">Completed</option>
                  <option value="From AE">From AE</option>
                  <option value="Sent to AE">Sent to AE</option>
                </select></td>
            </tr>
            <tr>
                <td>Date Request received</td>
                <td><input type="text" id="DateRec" name="DateRec"></td>
                <td colspan="2">Start Date</td>
                <td colspan="2"><input type="text" id="startD" name="startD"></td>
            </tr>
            <tr>
                <td>Date assigned</td>
                <td><input type="text" id="AssignedD" name="AssignedD"></td>
                <td colspan="2">Date file sent to AE</td>
                <td colspan="2"><input type="text" id="sentToAE" name="sentToAE"></td>
            </tr>
            <tr>
                <td>Date response from AE</td>
                <td><input type="text" id="RespFrmAE" name="RespFrmAE"></td>
                <td colspan="2">Date completed --VWR</td>
                <td colspan="2"><input type="text" id="VWRCmp" name="VWRCmp"></td>
            </tr>
            <tr>
                <td>Assigned to PS</td>
                <td><select name="PS" id="PS">
                <option value="" disabled selected>Select your option</option>
                <option value="Amreen, Fatima (GGO)">Amreen, Fatima (GGO)</option>
                <option value="Attarwala, Nisrin (GGO)">Attarwala, Nisrin (GGO)</option>
                <option value="Balam, Santhoshini (GGO)">Balam, Santhoshini (GGO)</option>
                <option value="Bongu, Shalini (GGO)">Bongu, Shalini (GGO)</option>
                <option value="Gaddam, Sandesh R. (GGO)">Gaddam, Sandesh R. (GGO)</option>
                <option value="Grace, Shalom (GGO)">Grace, Shalom (GGO)</option>
                <option value="Johney, Liya M. (GGO)">Johney, Liya M. (GGO)</option>
                <option value="N, Steven (GGO)">N, Steven (GGO)</option>
                <option value="Varghese, Shebin D. (GGO)">Varghese, Shebin D. (GGO)</option>
              </select></td>
                <td colspan="2">Time Estimate</td>
                <td colspan="2"><input type="text" name="TEst" id="TEst"></td>
            </tr>
            <tr>
                <td>Units</td>
                <td><input type="text" name="Units" id="Units"></td>
                <td colspan="2">Date file needs to be sent to Vendor (VWR)</td>
                <td colspan="2"><input type="text" name="VWR" id="VWR"></td>
            </tr>
            <tr>
                <td>Internal Errors</td>
                <td><input type="text" name="IE" id="IE"></td>
                <td>Review Date</td>
                <td><input type="text" id="RevDate" name="RevDate"></td>
                <td>Review Sent (Yes/No)</td>
                <td><select name="ReviewS" id="ReviewS">
                  <option value="" disabled selected>Select your option</option>
                  <option value="Yes">Yes</option>
                  <option value="No">No</option>
                </select></td>
            </tr>
            <tr>
            <td><input type="submit" value="Submit"></td>
            </tr>
        </table>
    </div>
<script type="text/javascript">

$(function() {
    $( "#DateRec" ).datepicker({ dateFormat: "mm-dd-y" }).val(); 
});
$(function() {
    $( "#AssignedD" ).datepicker({ dateFormat: "mm-dd-y" }).val(); 
});
$(function() {
    $( "#RespFrmAE" ).datepicker({ dateFormat: "mm-dd-y" }).val(); 
});
$(function() {
    $( "#RevDate" ).datepicker({ dateFormat: "mm-dd-y" }).val(); 
});
$(function() {
    $( "#sentToAE" ).datepicker({ dateFormat: "mm-dd-y" }).val(); 
});
$(function() {
    $( "#VWRCmp" ).datepicker({ dateFormat: "mm-dd-y" }).val(); 
});
$(function() {
    $( "#startD" ).datepicker({ dateFormat: "mm-dd-y" }).val(); 
});
</script>
</form>
</body>
</html>

并将数据提交到以下jsp。

<%@page import="java.sql.*"%>
<%
Connection con = null;
Statement stmnt = null;
try
{

    String as=request.getParameter("comments");
    int a=Integer.parseInt(as);
    String bs=request.getParameter("updatedl");
    int b=Integer.parseInt(bs);
    String cs=request.getParameter("sid");
    int c=Integer.parseInt(cs);
    String d=request.getParameter("desc");
    String e=request.getParameter("pubcode");
    String f=request.getParameter("Type");
    String g=request.getParameter("status");
    String h=request.getParameter("DateRec");
    String i=request.getParameter("startD");
    String j=request.getParameter("AssignedD");
    String k=request.getParameter("sentToAE");
    String l=request.getParameter("RespFrmAE");
    String m=request.getParameter("VWRCmp");
    String n=request.getParameter("PS");
    String o=request.getParameter("TEst");
    String ps1=request.getParameter("Units");
    int p=Integer.parseInt(ps1);
    String q=request.getParameter("VWR");
    String rs=request.getParameter("IE");
    int r=Integer.parseInt(rs);
    String s=request.getParameter("RevDate");
    String t=request.getParameter("ReviewS");


Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
con = DriverManager.getConnection( "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=C:/jus/Excel1.xls; ReadOnly=False;");


stmnt = con.createStatement(); 
//String query="select column_name from [Feb$[";
String query = "insert into [Feb$] ([comments],[No of lines updated in PSIS],[Shipment ID],"+
"[SAP TXT Description],[Phoenix Pub Code], [Product Type], [Status of the job],[Date Request received],"+
"[Start Date], [Date assigned],[Date file sent to AE],[Date response from AE],"+
"[Date completed --VWR], [Assigned to PS], [Time Estimate],[Units], [Date file needs to be sent to Vendor (VWR)],"+
"[Internal Errors],[Review Date],[Review Sent (Yes/No)]) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(query);
ps.setInt(1,a);
ps.setInt(2,b);
ps.setInt(3,c);
ps.setString(4,d);
ps.setString(5,e);
ps.setString(6,f);
ps.setString(7,g);
ps.setString(8,h);
ps.setString(9,i);
ps.setString(10,j);
ps.setString(11,k);
ps.setString(12,l);
ps.setString(13,m);
ps.setString(14,n);
ps.setString(15,o);
ps.setInt(16,p);
ps.setString(17,q);
ps.setInt(18,r);
ps.setString(19,s);
ps.setString(20,t);

int new1=ps.executeUpdate();

}
catch( Exception e )
{
out.println( e );
}
finally
{
try
{
stmnt.close();
con.close();
}
catch( Exception e )
{
out.println( e );
}
}

        %>

在这里,当我点击提交时,它给了我以下的例外。

java.sql.SQLException: [Microsoft][ODBC Excel Driver] Data type mismatch in criteria expression.

任何人都可以让我知道为什么我得到这个例外以及我哪里出错了。

由于

0 个答案:

没有答案