public void insert(Articles articles) throws Exception {
DBConnection dbc = new DBConnection();
sql = "insert into articles(title,date,hit,content,aclassify1,aclassify2,aclassify1name,aclassify2name,isparticles,istop) values(?,?,0,?,?,?,?,?,?,?)";
String sub = "";
try {
if (articles.getIsparticles() == 1) {
sub = this.subString(articles.getContent());
}// 处理图片新闻
pstm = dbc.getConnection().prepareStatement(sql);
pstm.setString(1, articles.getTitle());
pstm.setString(2, articles.getDate());
pstm.setString(3, articles.getContent());
pstm.setInt(4, articles.getAclassify1());
pstm.setInt(5, articles.getAclassify2());
pstm.setString(6, articles.getAclassify1name());
pstm.setString(7, articles.getAclassify2name());
pstm.setInt(8, articles.getIsparticles());
if (articles.getIsparticles() == 1) {
articles.setPhotourl(sub);
}// 处理图片新闻
pstm.setString(9, articles.getPhotourl());
pstm.setInt(10, articles.getIstop());
pstm.executeUpdate();
pstm.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
// dbc.close();
}
}<%@ page language="java" pageEncoding="utf-8" import="java.util.*,net.fckeditor.*"%>
<%@ include file="/inc/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'articles_add.jsp' starting page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/getType.js"></script>
<script type="text/javascript" src="js/calendar.js"></script>
<script type="text/javascript" src="ckeditor/cheditor.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script language = "JavaScript">
var onecount;
subcat = new Array();
function changelocation(locationid)
{
document.addARTICLES.SmallClassName.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.addARTICLES.SmallClassName.options[document.addARTICLES.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
function CheckForm()
{
document.addARTICLES.cnWords.value = document.frames.eWebEditor1.getHTML(true);
document.addARTICLES.imageNum.value = document.frames.cnEditBox.document.all("editImageNum").value;
document.addARTICLES.editFirstImageName.value = document.frames.cnEditBox.document.all("editFirstImageName").value;
if (document.addNEWS.title.value.length == 0) {
alert("文章标题没有填写.");
document.addARTICLES.title.focus();
return false;
}
if (document.addARTICLES.user.value.length == 0) {
alert("文章发布人没有填写");
document.addARTICLES.user.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<%
// 进行乱码处理
request.setCharacterEncoding("utf-8") ;
%>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top">
<table width="90%" border="0" cellpadding="3" cellspacing="1" bgcolor="#DEDFDE" class="table_southidc">
<form name="addARTICLES" method="post" action="articles?status=insert" onSubmit="return CheckForm();">
<tr>
<td height="30" colspan="2" align="center" bgcolor="#f7f7f7" class="back_southidc"><strong>增 加 文章</strong></td>
</tr>
<tr bgcolor="#ECF5FF">
<td width="100" height="25" bgcolor="#FFFFFF" id="changetitle">文章标题:
</td>
<td width="400" bgcolor="#FFFFFF">
<input name="title" type="text" class="input" size="50">
<font color="#ff6600">*</font>
</td>
</tr> <tr bgcolor="#ECF5FF">
<td height="25" bgcolor="#FFFFFF">文章类别:</td>
<td ><jsp:include page="getClassify.jsp"/></td>
</tr>
<tr bgcolor="#EEF4EA">
<td ><label>
<div >添加时间:</div>
</label></td>
<td colspan="3" >
<div>
<input type="text" id="articlesTime" name="date" onfocus="setday(this)" allownull="false" class="validate[required]"/>
</div>
</td>
</tr>
<tr>
<td><label>
<div >是否置顶:</div>
</label></td>
<td colspan="3" >
<div >
<select name="istop">
<option value="0">不置顶</option>
<option value="1">置顶</option>
</select>
</div>
</td>
</tr> <tr bgcolor="#ECF5FF">
<td height="25" colspan="2" valign="top" bgcolor="#FFFFFF">文章内容: <font color="#ff6600">*</font> </td>
</tr>
<tr>
<td>
<label for="textfield"></label>
<label for="textarea"></label>
<textarea name="content" id="content" cols="95" row="30"></textarea>
<script type="text/javascript">
CKEDTTOR.replace('content',
{
skin:'kama', language:'zh-cn'
});</script>
</td>
</tr> <tr bgcolor="#FFFFFF">
<td height="30" colspan="2" align="center">
<input type="submit" name="Submit" value="提交" class="input">
<input type="reset" name="Submit2" value="重置" class="input">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="30" colspan="2" align="center"> </td>
</tr>
</table></table>
</body>
</html>报错:
java.sql.SQLException: Parameter index out of bounds. 10 is not between valid values of 1 and 9
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ServerPreparedStatement.getBinding(ServerPreparedStatement.java:768)
at com.mysql.jdbc.ServerPreparedStatement.setInt(ServerPreparedStatement.java:1778)
at hjj.articles.ArticlesDAO.insert(ArticlesDAO.java:43)
at hjj.articles.ArticlesServlet.insert(ArticlesServlet.java:221)
at hjj.articles.ArticlesServlet.manage(ArticlesServlet.java:56)
at hjj.articles.ArticlesServlet.doPost(ArticlesServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)Mysql
DBConnection dbc = new DBConnection();
sql = "insert into articles(title,date,hit,content,aclassify1,aclassify2,aclassify1name,aclassify2name,isparticles,istop) values(?,?,0,?,?,?,?,?,?,?)";
String sub = "";
try {
if (articles.getIsparticles() == 1) {
sub = this.subString(articles.getContent());
}// 处理图片新闻
pstm = dbc.getConnection().prepareStatement(sql);
pstm.setString(1, articles.getTitle());
pstm.setString(2, articles.getDate());
pstm.setString(3, articles.getContent());
pstm.setInt(4, articles.getAclassify1());
pstm.setInt(5, articles.getAclassify2());
pstm.setString(6, articles.getAclassify1name());
pstm.setString(7, articles.getAclassify2name());
pstm.setInt(8, articles.getIsparticles());
if (articles.getIsparticles() == 1) {
articles.setPhotourl(sub);
}// 处理图片新闻
pstm.setString(9, articles.getPhotourl());
pstm.setInt(10, articles.getIstop());
pstm.executeUpdate();
pstm.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
// dbc.close();
}
}<%@ page language="java" pageEncoding="utf-8" import="java.util.*,net.fckeditor.*"%>
<%@ include file="/inc/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'articles_add.jsp' starting page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/getType.js"></script>
<script type="text/javascript" src="js/calendar.js"></script>
<script type="text/javascript" src="ckeditor/cheditor.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script language = "JavaScript">
var onecount;
subcat = new Array();
function changelocation(locationid)
{
document.addARTICLES.SmallClassName.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.addARTICLES.SmallClassName.options[document.addARTICLES.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
function CheckForm()
{
document.addARTICLES.cnWords.value = document.frames.eWebEditor1.getHTML(true);
document.addARTICLES.imageNum.value = document.frames.cnEditBox.document.all("editImageNum").value;
document.addARTICLES.editFirstImageName.value = document.frames.cnEditBox.document.all("editFirstImageName").value;
if (document.addNEWS.title.value.length == 0) {
alert("文章标题没有填写.");
document.addARTICLES.title.focus();
return false;
}
if (document.addARTICLES.user.value.length == 0) {
alert("文章发布人没有填写");
document.addARTICLES.user.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<%
// 进行乱码处理
request.setCharacterEncoding("utf-8") ;
%>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top">
<table width="90%" border="0" cellpadding="3" cellspacing="1" bgcolor="#DEDFDE" class="table_southidc">
<form name="addARTICLES" method="post" action="articles?status=insert" onSubmit="return CheckForm();">
<tr>
<td height="30" colspan="2" align="center" bgcolor="#f7f7f7" class="back_southidc"><strong>增 加 文章</strong></td>
</tr>
<tr bgcolor="#ECF5FF">
<td width="100" height="25" bgcolor="#FFFFFF" id="changetitle">文章标题:
</td>
<td width="400" bgcolor="#FFFFFF">
<input name="title" type="text" class="input" size="50">
<font color="#ff6600">*</font>
</td>
</tr> <tr bgcolor="#ECF5FF">
<td height="25" bgcolor="#FFFFFF">文章类别:</td>
<td ><jsp:include page="getClassify.jsp"/></td>
</tr>
<tr bgcolor="#EEF4EA">
<td ><label>
<div >添加时间:</div>
</label></td>
<td colspan="3" >
<div>
<input type="text" id="articlesTime" name="date" onfocus="setday(this)" allownull="false" class="validate[required]"/>
</div>
</td>
</tr>
<tr>
<td><label>
<div >是否置顶:</div>
</label></td>
<td colspan="3" >
<div >
<select name="istop">
<option value="0">不置顶</option>
<option value="1">置顶</option>
</select>
</div>
</td>
</tr> <tr bgcolor="#ECF5FF">
<td height="25" colspan="2" valign="top" bgcolor="#FFFFFF">文章内容: <font color="#ff6600">*</font> </td>
</tr>
<tr>
<td>
<label for="textfield"></label>
<label for="textarea"></label>
<textarea name="content" id="content" cols="95" row="30"></textarea>
<script type="text/javascript">
CKEDTTOR.replace('content',
{
skin:'kama', language:'zh-cn'
});</script>
</td>
</tr> <tr bgcolor="#FFFFFF">
<td height="30" colspan="2" align="center">
<input type="submit" name="Submit" value="提交" class="input">
<input type="reset" name="Submit2" value="重置" class="input">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="30" colspan="2" align="center"> </td>
</tr>
</table></table>
</body>
</html>报错:
java.sql.SQLException: Parameter index out of bounds. 10 is not between valid values of 1 and 9
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ServerPreparedStatement.getBinding(ServerPreparedStatement.java:768)
at com.mysql.jdbc.ServerPreparedStatement.setInt(ServerPreparedStatement.java:1778)
at hjj.articles.ArticlesDAO.insert(ArticlesDAO.java:43)
at hjj.articles.ArticlesServlet.insert(ArticlesServlet.java:221)
at hjj.articles.ArticlesServlet.manage(ArticlesServlet.java:56)
at hjj.articles.ArticlesServlet.doPost(ArticlesServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)Mysql
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货