简单问题,请多多指教(50分)

  • 主题发起人 主题发起人 minewdy
  • 开始时间 开始时间
M

minewdy

Unregistered / Unconfirmed
GUEST, unregistred user!
我刚做作了很简单的JSP ,功能就是查询(通过 ODBC桥),查询10个字段 然后显
示其中的8个字段,他总是提示我
javax.servlet.ServletException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
但我如果只显示其中的7个字段,就没有问题,

望各位多多指教,小的刚学JAVA
 
不会把,这个问题难道大家都没有碰到过么
 
代码贴出来。不然怎么看?
 
可能是数据库类型不匹配,或索引问题.
 
代码太长了,不过我还是贴出来吧,
我总觉得我的代码没有设么问题,数据类型不匹配到是有可能,但我不知道如何解决
我的数据库没有索引
以下是代码
<%@ page language="java" contentType="text/html;
charset=8859_1" import="java.sql.*"%>
<%@ page import="java.io.*" import="java.util.*"%>
<%@ page session="true" %>
<%
//数据连接
String MM_bomprice_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
String MM_bomprice_USERNAME = "minewdy";
String MM_bomprice_PASSWORD = "minewdy";
String MM_bomprice_STRING = "jdbc:odbc:assure";
String MM_tablename="";
String MM_pono="";
String MM_vend_no="";
String MM_partno="";
String MM_date1="";
String MM_date2="";
String MM_querycon ="", MM_sortflag="",MM_setparameter="",MM_sortcon="";
String MM_pono_sortflag ="",MM_vend_no_sortflag="",MM_podate_sortflag="" ,MM_partno_sortflag="";
String MM_setcommon_pono="partno=%&amp;vend_no=%",MM_setcommon_vend_no="partno=%&amp;pono=% ";
String MM_test="";
//查询条件取值 排序查询条件的设置
if (request.getParameter("pono") !=null) {
MM_pono = (String)request.getParameter("pono");
MM_setparameter=MM_setparameter+"pono="+MM_pono;
}
if (request.getParameter("vend_no") !=null) {
MM_vend_no = (String)request.getParameter("vend_no");
if (MM_setparameter !=null)
MM_setparameter=MM_setparameter+"&amp;vend_no="+MM_vend_no;
else
MM_setparameter=MM_setparameter+"vend_no="+MM_vend_no;
}
if (request.getParameter("partno") !=null) {
MM_partno = (String)request.getParameter("partno");
if (MM_setparameter!=null)
MM_setparameter=MM_setparameter+"&amp;partno="+MM_partno;
else
MM_setparameter=MM_setparameter+"partno="+MM_partno;
}
if (request.getParameter("date1") !=null) {
MM_date1 = (String)request.getParameter("date1");
if (MM_setparameter!=null)
MM_setparameter=MM_setparameter+"&amp;date1="+MM_date1;
else
MM_setparameter=MM_setparameter+"date2="+MM_date1;
}
if (request.getParameter("date2") !=null) {
MM_date2 = (String)request.getParameter("date2");
if (MM_setparameter!=null)
MM_setparameter=MM_setparameter+"&amp;date1="+MM_date2;
else
MM_setparameter=MM_setparameter+"date2="+MM_date2;
}
//查询年标志设置
if (request.getParameter("MM_pono_sortflag")!=null) {
MM_pono_sortflag=(String)request.getParameter("MM_pono_sortflag");
if (session.getAttribute("MM_pono_sortflag")=="1"){
session.setAttribute("MM_pono_sortflag","2");
MM_sortcon="order by pono ASC";
}
else
{
session.setAttribute("MM_pono_sortflag","1");
MM_sortcon="order by pono DESC";
}
}
if (request.getParameter("MM_podate_sortflag")!=null) {
MM_pono_sortflag=(String)request.getParameter("MM_podate_sortflag");
if (session.getAttribute("MM_podate_sortflag")=="1"){
session.setAttribute("MM_podate_sortflag","2");
MM_sortcon="order by podate ASC";
}
else
{
session.setAttribute("MM_podate_sortflag","1");
MM_sortcon="order by podate DESC";
}
}
if (request.getParameter("MM_vend_no_sortflag")!=null) {
MM_vend_no_sortflag=(String)request.getParameter("MM_vend_no_sortflag");
if (session.getAttribute("MM_vend_no_sortflag")=="1"){
session.setAttribute("MM_vend_no_sortflag","2");
MM_sortcon="order by vend_no ASC";
}
else
{
session.setAttribute("MM_vend_no_sortflag","1");
MM_sortcon="order by vend_no DESC";
}
}
if (request.getParameter("MM_partno_sortflag")!=null) {
MM_partno_sortflag=(String)request.getParameter("MM_partno_sortflag");
if (session.getAttribute("MM_partno_sortflag")=="1"){
session.setAttribute("MM_partno_sortflag","2");
MM_sortcon="order by partno ASC";
}
else
{
session.setAttribute("MM_partno_sortflag","1");
MM_sortcon="order by partno DESC";
}
}
if (MM_pono_sortflag==null &amp;&amp;
MM_partno_sortflag==null &amp;&amp;
MM_vend_no_sortflag==null &amp;&amp;
MM_podate_sortflag==null)
MM_sortcon="order by podate";
//查询条件设置
if (MM_pono!=null) MM_querycon=MM_querycon+"(pono like '%"+MM_pono+"%')";
if (MM_vend_no!=null &amp;&amp;
MM_querycon!=null) MM_querycon=MM_querycon+" and (vend_no like '%" +MM_vend_no+"%')";
else
MM_querycon="(vend_no like '%" +MM_vend_no+"%')";
if (MM_partno!=null &amp;&amp;
MM_querycon!=null) MM_querycon=MM_querycon+" and (partno like '%"+MM_partno+"%')";
else
MM_querycon="(partno like '%"+MM_partno+"%')";
if (MM_date1 !="") {
if (MM_date2 !=""){
if (MM_querycon!=null)
MM_querycon=MM_querycon+"and (podate>="+MM_date1+") and (podate<="+MM_date2+")";
else
MM_querycon="(podate>="+MM_date1+") and (podate<="+MM_date2+")";
}
}
if (request.getParameter("tablename") !=null) {MM_tablename = (String)request.getParameter("tablename");}
session.setAttribute("tablename",MM_tablename);
Driver DriverRecordset1 = (Driver)Class.forName(MM_bomprice_DRIVER).newInstance();
Connection ConnRecordset1 = DriverManager.getConnection(MM_bomprice_STRING,MM_bomprice_USERNAME,MM_bomprice_PASSWORD);
PreparedStatement StatementRecordset1 = ConnRecordset1.prepareStatement("SELECT * FROM "+MM_tablename+" WHERE "+MM_querycon+" "+MM_sortcon);
//PreparedStatement StatementRecordset1 = ConnRecordset1.prepareStatement("SELECT * FROM "+MM_tablename+" WHERE pono LIKE '%" + Recordset1__MMColParam + "%' ORDER BY podate ASC");
ResultSet Recordset1 = StatementRecordset1.executeQuery();
boolean Recordset1_isEmpty = !Recordset1.next();
boolean Recordset1_hasData = !Recordset1_isEmpty;
Object Recordset1_data;
int Recordset1_numRows = 0;
int Repeat1__numRows = 18;
int Repeat1__index = 0;
Recordset1_numRows += Repeat1__numRows;
// *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
int Recordset1_first = 1;
int Recordset1_last = 1;
int Recordset1_total = -1;
if (Recordset1_isEmpty) {
Recordset1_total = Recordset1_first = Recordset1_last = 0;
}
//set the number of rows displayed on this page
if (Recordset1_numRows == 0) {
Recordset1_numRows = 1;
}

// *** Recordset Stats: if wedo
n't know the record count, manually count them
if (Recordset1_total == -1) {
// count the total records by iterating through the recordset
for (Recordset1_total = 1;
Recordset1.next();
Recordset1_total++);
// reset the cursor to the begin
ning
Recordset1.close();
Recordset1 = StatementRecordset1.executeQuery();
Recordset1_hasData = Recordset1.next();
// set the number of rows displayed on this page
if (Recordset1_numRows < 0 || Recordset1_numRows > Recordset1_total) {
Recordset1_numRows = Recordset1_total;
}
// set the first and last displayed record
Recordset1_first = Math.min(Recordset1_first, Recordset1_total);
Recordset1_last = Math.min(Recordset1_first + Recordset1_numRows - 1, Recordset1_total);
}
String MM_paramName = "";
// *** Move To Record and Go To Record: declare variables
ResultSet MM_rs = Recordset1;
int MM_rsCount = Recordset1_total;
int MM_size = Recordset1_numRows;
String MM_uniqueCol = "";
MM_paramName = "";
int MM_offset = 0;
boolean MM_atTotal = false;
boolean MM_paramIsDefined = (MM_paramName.length() != 0 &amp;&amp;
request.getParameter(MM_paramName) != null);

// *** Move To Record: handle 'index' or 'offset' parameter
if (!MM_paramIsDefined &amp;&amp;
MM_rsCount != 0) {
//use index parameter if defined, otherwise use offset parameter
String r = request.getParameter("index");
if (r==null) r = request.getParameter("offset");
if (r!=null) MM_offset = Integer.parseInt(r);
// if we have a record count, check if we are past the end of the recordset
if (MM_rsCount != -1) {
if (MM_offset >= MM_rsCount || MM_offset == -1) { // past end or move last
if (MM_rsCount % MM_size != 0) // last page not a full repeat region
MM_offset = MM_rsCount - MM_rsCount % MM_size;
else
MM_offset = MM_rsCount - MM_size;
}
}
//move the cursor to the selected record
int i;
for (i=0;
Recordset1_hasData &amp;&amp;
(i < MM_offset || MM_offset == -1);
i++) {
Recordset1_hasData = MM_rs.next();
}
if (!Recordset1_hasData) MM_offset = i;
// set MM_offset to the last possible record
}

// *** Move To Record: if wedo
nt know the record count, check the display range
if (MM_rsCount == -1) {
// walk to the end of the display range for this page
int i;
for (i=MM_offset;
Recordset1_hasData &amp;&amp;
(MM_size < 0 || i < MM_offset + MM_size);
i++) {
Recordset1_hasData = MM_rs.next();
}
// if we walked off the end of the recordset, set MM_rsCount and MM_size
if (!Recordset1_hasData) {
MM_rsCount = i;
if (MM_size < 0 || MM_size > MM_rsCount) MM_size = MM_rsCount;
}
// if we walked off the end, set the offset based on page size
if (!Recordset1_hasData &amp;&amp;
!MM_paramIsDefined) {
if (MM_offset > MM_rsCount - MM_size || MM_offset == -1) { //check if past end or last
if (MM_rsCount % MM_size != 0) //last page has less records than MM_size
MM_offset = MM_rsCount - MM_rsCount % MM_size;
else
MM_offset = MM_rsCount - MM_size;
}
}
// reset the cursor to the begin
ning
Recordset1.close();
Recordset1 = StatementRecordset1.executeQuery();
Recordset1_hasData = Recordset1.next();
MM_rs = Recordset1;
// move the cursor to the selected record
for (i=0;
Recordset1_hasData &amp;&amp;
i < MM_offset;
i++) {
Recordset1_hasData = MM_rs.next();
}
}
// *** Move To Record: update recordset stats
// set the first and last displayed record
Recordset1_first = MM_offset + 1;
Recordset1_last = MM_offset + MM_size;
if (MM_rsCount != -1) {
Recordset1_first = Math.min(Recordset1_first, MM_rsCount);
Recordset1_last = Math.min(Recordset1_last, MM_rsCount);
}
// set the boolean used by hide region to check if we are on the last record
MM_atTotal = (MM_rsCount != -1 &amp;&amp;
MM_offset + MM_size >= MM_rsCount);
// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
String MM_keepBoth,MM_keepURL="",MM_keepForm="",MM_keepNone="";
String[] MM_removeList = { "index", MM_paramName };
// create the MM_keepURL string
if (request.getQueryString() != null) {
MM_keepURL = '&amp;' + request.getQueryString();
for (int i=0;
i < MM_removeList.length &amp;&amp;
MM_removeList.length() != 0;
i++) {
int start = MM_keepURL.indexOf(MM_removeList) - 1;
if (start >= 0 &amp;&amp;
MM_keepURL.charAt(start) == '&amp;' &amp;&amp;
MM_keepURL.charAt(start + MM_removeList.length() + 1) == '=') {
int stop = MM_keepURL.indexOf('&amp;', start + 1);
if (stop == -1) stop = MM_keepURL.length();
MM_keepURL = MM_keepURL.substring(0,start) + MM_keepURL.substring(stop);
}
}
}
// add the Form variables to the MM_keepForm string
if (request.getParameterNames().hasMoreElements()) {
java.util.Enumeration items = request.getParameterNames();
while (items.hasMoreElements()) {
String nextItem = (String)items.nextElement();
boolean found = false;
for (int i=0;
!found &amp;&amp;
i < MM_removeList.length;
i++) {
if (MM_removeList.equals(nextItem)) found = true;
}
if (!found &amp;&amp;
MM_keepURL.indexOf('&amp;' + nextItem + '=') == -1) {
MM_keepForm = MM_keepForm + '&amp;' + nextItem + '=' + java.net.URLEncoder.encode(request.getParameter(nextItem));
}
}
}
// create the Form + URL string and remove the intial '&amp;' from each of the strings
MM_keepBoth = MM_keepURL + MM_keepForm;
if (MM_keepBoth.length() > 0) MM_keepBoth = MM_keepBoth.substring(1);
if (MM_keepURL.length() > 0) MM_keepURL = MM_keepURL.substring(1);
if (MM_keepForm.length() > 0) MM_keepForm = MM_keepForm.substring(1);

// *** Move To Record: set the strings for the first, last, next, and previous links
String MM_moveFirst,MM_moveLast,MM_moveNext,MM_movePrev;
{
String MM_keepMove = MM_keepBoth;
// keep both Form and URL parameters for moves
String MM_moveParam = "index=";
// if the page has a repeated region, remove 'offset' from the maintained parameters
if (MM_size > 1) {
MM_moveParam = "offset=";
int start = MM_keepMove.indexOf(MM_moveParam);
if (start != -1 &amp;&amp;
(start == 0 || MM_keepMove.charAt(start-1) == '&amp;')) {
int stop = MM_keepMove.indexOf('&amp;', start);
if (start == 0 &amp;&amp;
stop != -1) stop++;
if (stop == -1) stop = MM_keepMove.length();
if (start > 0) start--;
MM_keepMove = MM_keepMove.substring(0,start) + MM_keepMove.substring(stop);
}
}
// set the strings for the move to links
StringBuffer urlStr = new StringBuffer(request.getRequestURI()).append('?').append(MM_keepMove);
if (MM_keepMove.length() > 0) urlStr.append('&amp;');
urlStr.append(MM_moveParam);
MM_moveFirst = urlStr + "0";
MM_moveLast = urlStr + "-1";
MM_moveNext = urlStr + Integer.toString(MM_offset+MM_size);
MM_movePrev = urlStr + Integer.toString(Math.max(MM_offset-MM_size,0));
}
out.print("<title>价格对比-----数据操作</title>");
out.print("<body bgcolor=#FFFFFF>");
out.print("<table width=800 border=1 cellspacing=0 cellpadding=0>");
out.print("<tr bgcolor=#00FFFF align=center valign=middle>");
out.print("<td height=17><font size=2><A HREF=index.jsp?tablename="+session.getAttribute("tablename")+"&amp;MM_pono_sortflag="+session.getAttribute("MM_pono_sortflag")+"&amp;"+MM_setparameter+">订单号</A></font></td>");
out.print("<td height=17><font size=2><A HREF=index.jsp?tablename="+session.getAttribute("tablename")+"&amp;MM_podate_sortflag="+session.getAttribute("MM_podate_sortflag")+"&amp;"+MM_setparameter+">下订单日期</A></font></td>");
out.print("<td height=17><font size=2><A HREF=index.jsp?tablename="+session.getAttribute("tablename")+"&amp;MM_vend_no_sortflag="+session.getAttribute("MM_vend_no_sortflag")+"&amp;"+MM_setparameter+">供应商</A></font></td>");
out.print("<td height=17><font size=2><A HREF=index.jsp?tablename="+session.getAttribute("tablename")+"&amp;MM_partno_sortflag="+session.getAttribute("MM_partno_sortflag")+"&amp;"+MM_setparameter+">材料编号</A></font></td>");
out.print("<td height=17><font size=2>订单数量</font></td>");
out.print("<td height=17><font size=2>收货数量</font></td>");
out.print("<td height=17><font size=2>价格</font></td>");
out.print("<td height=17><font size=2>币种</font></td>");
out.print("</tr>");
while ((Recordset1_hasData)&amp;&amp;(Repeat1__numRows-- != 0)) {
out.print("<tr bgcolor=#00CCFF align=center valign=middle>");
String pono =Recordset1.getObject("pono").toString();
String vend_no =Recordset1.getObject("vend_no").toString();
String partno =Recordset1.getObject("partno").toString();
String curr =Recordset1.getObject("curr").toString();
String podate =Recordset1.getObject("podate").toString();
String qty =Recordset1.getObject("qty").toString();
String rqty =Recordset1.getObject("rqty").toString();
String uprice =Recordset1.getObject("uprice").toString();
out.print("<td><font size=2><A HREF=index.jsp?tablename="+session.getAttribute("tablename")+"&amp;pono="+pono+"&amp;"+MM_setcommon_pono+">"+pono+"</A></font></td>");
out.print("<td><font size=2>"+podate+"</font></td>");
out.print("<td><font size=2><A HREF=index.jsp?tablename="+session.getAttribute("tablename")+"&amp;vend_no="+vend_no+"&amp;"+MM_setcommon_vend_no+">"+vend_no+"</A></font></td>");
out.print("<td><font size=2><A HREF=index.jsp?tablename="+session.getAttribute("tablename")+"&amp;partno="+partno+">"+partno+"</A></font></td>");
out.print("<td><font size=2>"+qty+"</font></td>");
out.print("<td><font size=2>"+rqty+"</font></td>");
out.print("<td><font size=2>"+uprice+"</font></td>");
out.print("<td><font size=2>"+curr+"</font></td>");
out.print("</tr>");
Repeat1__index++;
Recordset1_hasData = Recordset1.next();
}
%>
</table>
<div align="center">
<p align="center"><font size="2">当前显示第<%=(Recordset1_first)%> 条到第<%=(Recordset1_last)%>条记录,共搜到<%=(Recordset1_total)%>条记录</font></p>
<table border="0" width="31%" align="center">
<tr>
<td width="23%" align="center"> <font size="2">
<% if (MM_offset !=0) { %>
<a href="<%=MM_moveFirst%>">第一页</a>
<% } /* end MM_offset != 0 */ %>
</font></td>
<td width="31%" align="center"> <font size="2">
<% if (MM_offset !=0) { %>
<a href="<%=MM_movePrev%>">上一页</a>
<% } /* end MM_offset != 0 */ %>
</font></td>
<td width="23%" align="center"> <font size="2">
<% if (!MM_atTotal) { %>
<a href="<%=MM_moveNext%>">下一页</a>
<% } /* end !MM_atTotal */ %>
</font></td>
<td width="23%" align="center"> <font size="2">
<% if (!MM_atTotal) { %>
<a href="<%=MM_moveLast%>">最后一页</a>
<% } /* end !MM_atTotal */ %>
</font></td>
</tr>
</table>
查询条件:<%= MM_querycon%>
查询标志:<%=session.getAttribute("MM_pono_sortflag")%>
asdf:<%= MM_test%>
<%
Recordset1.close();
ConnRecordset1.close();
%>
</div>
 
以下是我的数据库创建的 SQL 语句
CREATE TABLE [minewdy].[tv_thisyear] (
[pono] [varchar] (20) NULL ,
[itmno] [float] NULL ,
[podate] [datetime] NULL ,
[vend_no] [varchar] (20) NULL ,
[pterm] [varchar] (2) NULL ,
[dlydate] [datetime] NULL ,
[partno] [varchar] (20) NULL ,
[qty] [real] NULL ,
[rqty] [real] NULL ,
[rjqty] [real] NULL ,
[curr] [varchar] (6) NULL ,
[uprice] [float] NULL ,
[revise] [varchar] (2) NULL ,
[ptype] [varchar] (2) NULL ,
[vat] [float] NULL
) ON [PRIMARY]
GO
 
我是用 ODBC 桥 去连接数据库的,看源代码应该可以知道,就在开始的部分
以上的代码在运行的时候就是出现问题的了
希望哪位大侠可以帮我解决这个问题
 
你代码没问题,能通过编译,没发现你说的问题。
 
这就没有办法了,在我的机器上,怎么都出问题,
哇,我是不是该将我的机器重装啊,
这岂不是很惨,
 
确实是太长了!,不过从错误看好像是下标问题!JDBC的下标是从1开始
或者是使用了与字段不匹配的类型,例如本来是getString的,你
使用getInt就会出错。
 
是驱动程序问题,后边说的是无效的光标等等。你可以试着改改关闭连接语句的位置
 
参考
http://www.java-cn.com
 
后退
顶部