<>第5章实例100
发表在JavaWeb图书答疑
2008-04-21
是否精华
是
否
版块置顶:
是
否
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="GB2312"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><%request.setCharacterEncoding("GB2312");%><%!
public Connection Con() {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection Con = DriverManager.getConnection("jdbc:odbc:ylxlam","sa","sa");
return Con;
}
catch(Exception e)
{
return null;
}
}
public int InsertSQL(String id,String name,String abc,String spec,
String sort,String unit,String price,String stock){
try
{
String SQL = "insert product (pID,pName,pShort,pSpec,pSort,pUnit,pPrice,pStock)"+
"values('"+id+"','"+name+"','"+abc+"','"+spec+"','"+sort+"','"+unit+"','"+price+"','"+stock+"')";
Connection Con = Con();
Statement Smt = Con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
int UpdateCount = Smt.executeUpdate(SQL);
return UpdateCount;
}
catch(SQLException e)
{
System.out.println("记录插入失败!");
return 0;
}
}
%>
<SCRIPT language=javascript type=text/javascript>
function checkEmpty(form)
{
if(document.form.id.value=="")
{
alert("请将代有*号的信息添写完整!");
return false;
}
else
{
return true;
}
}
</SCRIPT>
<BASE href="<%=basePath%>">
<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"><!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<STYLE type=text/css>
<!--
.style1 {
font-size: 14px;
font-weight: bold;
color: #33FF00;
}
.style2 {
font-size: 12px;
color: #663399;
}
.style4 {font-size: 12}
.style5 {color: #FF0000}
-->
</STYLE>
<FORM name=form onsubmit="<% InsertSQL(request.getParameter(" action=/myjsp/WebRoot/insert1.jsp method=post % request.getParameter(?stock?)); request.getParameter(?unit?),request.getParameter(?price?), request.getParameter(?spec?),request.getParameter(?sort?), id?),request.getParameter(?name?),request.getParameter(?abc?),>">
<TABLE borderColor=#ffffff cellSpacing=0 borderColorDark=#ffffff cellPadding=0 width=408 align=center borderColorLight=#6633ff border=1>
<TBODY>
<TR>
<TD bgColor=#6633ff colSpan=2 height=34>
<DIV class=style1 align=center>产品资料录入</DIV></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>编号:</DIV></TD>
<TD height=17><INPUT name=id> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>名称:</DIV></TD>
<TD height=17><INPUT name=name> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>简称:</DIV></TD>
<TD height=17><INPUT name=abc></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>规格:</DIV></TD>
<TD height=17><INPUT name=spec> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>分类:</DIV></TD>
<TD height=17><INPUT name=sort></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>单位:</DIV></TD>
<TD height=17><INPUT name=unit> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>价格:</DIV></TD>
<TD height=17><INPUT name=price> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>库存:</DIV></TD>
<TD height=17><INPUT name=stock> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD colSpan=2 height=26>
<DIV align=center><INPUT type=submit value=提交 name=Submit> <INPUT type=reset value=重置 name=Submit2> </DIV></TD></TR>
<TR>
<TD colSpan=2 height=24>
<DIV class=style2 align=center>*请您添写真实信息!</DIV></TD></TR></TBODY></TABLE></FORM><BR>为什么这样插入SQL里还是乱码..我都已经照光盘的内容整个拷贝过来了..只是换成自己的数据库和改一些变量..为什么就是乱码呢?用光盘上的实例插入数据就正常..我真想不透!!
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><%request.setCharacterEncoding("GB2312");%><%!
public Connection Con() {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection Con = DriverManager.getConnection("jdbc:odbc:ylxlam","sa","sa");
return Con;
}
catch(Exception e)
{
return null;
}
}
public int InsertSQL(String id,String name,String abc,String spec,
String sort,String unit,String price,String stock){
try
{
String SQL = "insert product (pID,pName,pShort,pSpec,pSort,pUnit,pPrice,pStock)"+
"values('"+id+"','"+name+"','"+abc+"','"+spec+"','"+sort+"','"+unit+"','"+price+"','"+stock+"')";
Connection Con = Con();
Statement Smt = Con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
int UpdateCount = Smt.executeUpdate(SQL);
return UpdateCount;
}
catch(SQLException e)
{
System.out.println("记录插入失败!");
return 0;
}
}
%>
<SCRIPT language=javascript type=text/javascript>
function checkEmpty(form)
{
if(document.form.id.value=="")
{
alert("请将代有*号的信息添写完整!");
return false;
}
else
{
return true;
}
}
</SCRIPT>
<BASE href="<%=basePath%>">
<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"><!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<STYLE type=text/css>
<!--
.style1 {
font-size: 14px;
font-weight: bold;
color: #33FF00;
}
.style2 {
font-size: 12px;
color: #663399;
}
.style4 {font-size: 12}
.style5 {color: #FF0000}
-->
</STYLE>
<FORM name=form onsubmit="<% InsertSQL(request.getParameter(" action=/myjsp/WebRoot/insert1.jsp method=post % request.getParameter(?stock?)); request.getParameter(?unit?),request.getParameter(?price?), request.getParameter(?spec?),request.getParameter(?sort?), id?),request.getParameter(?name?),request.getParameter(?abc?),>">
<TABLE borderColor=#ffffff cellSpacing=0 borderColorDark=#ffffff cellPadding=0 width=408 align=center borderColorLight=#6633ff border=1>
<TBODY>
<TR>
<TD bgColor=#6633ff colSpan=2 height=34>
<DIV class=style1 align=center>产品资料录入</DIV></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>编号:</DIV></TD>
<TD height=17><INPUT name=id> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>名称:</DIV></TD>
<TD height=17><INPUT name=name> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>简称:</DIV></TD>
<TD height=17><INPUT name=abc></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>规格:</DIV></TD>
<TD height=17><INPUT name=spec> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>分类:</DIV></TD>
<TD height=17><INPUT name=sort></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>单位:</DIV></TD>
<TD height=17><INPUT name=unit> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>价格:</DIV></TD>
<TD height=17><INPUT name=price> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD>
<DIV class=style4 align=right>库存:</DIV></TD>
<TD height=17><INPUT name=stock> <SPAN class=style5>*</SPAN></TD></TR>
<TR>
<TD colSpan=2 height=26>
<DIV align=center><INPUT type=submit value=提交 name=Submit> <INPUT type=reset value=重置 name=Submit2> </DIV></TD></TR>
<TR>
<TD colSpan=2 height=24>
<DIV class=style2 align=center>*请您添写真实信息!</DIV></TD></TR></TBODY></TABLE></FORM><BR>为什么这样插入SQL里还是乱码..我都已经照光盘的内容整个拷贝过来了..只是换成自己的数据库和改一些变量..为什么就是乱码呢?用光盘上的实例插入数据就正常..我真想不透!!