以下是代码:源码太长,我为了让大家看懂,截了一些主要部分,剩下的都是大同小异,无伤大局。请多帮忙。现在发现我的所有插入页,好像都有这个问题!!
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
body,td,th {
color: #F7F7F7;
}
body {
background-color: #0099FF;
}
-->
</style></head><body>
<script Language="JavaScript">
function ChkFields() {
if (document.form1.MachineName11.value=='') {
window.alert ("请输入机械编号!")
document.form1.MachineName11.focus()
return false
}
if (document.form1.MachineNo.value=='') {
window.alert ("请输入机械编号!")
document.form1.MachineNo.focus()
return false
}
if (document.form1.InitValue.value=='') {
window.alert ("请输入预值!")
document.form1.InitValue.focus()
return false
}
return true
}
</script>
<p>您可以进行添加机械ID的操作:</p>
<form name="form1" method="post" action="" onsubmit="return ChkFields()">
<p>机械类别:
<select name="MachineSort11">
<Option value="土石方工程机械" selected>土石方工程机械
<Option value="路面工程机械">路面工程机械
<Option value="混凝土及灰浆机械">混凝土及灰浆机械
<Option value="水平运输机械">水平运输机械
<Option value="起重机垂直运输机械">起重机垂直运输机械
</select> <p>机械名称:
<select name="MachineName11">
<Option value="---">---土石方工程机械---
<Option value="推土机" selected>推土机
<Option value="铲运机">铲运机
<Option value="单斗挖掘机">单斗挖掘机
</select>
</p>
<p>机械的编号:
<input type="text" name="MachineNo">
</p>
<p>预值:
<input type="text" name="InitValue">
</p>
<p>
<input type="submit" name="Submit" value="添加">
</p>
</form>
<% //获取新的信息。
String ms="000";
String mn="000";
String MachineSort=request.getParameter("MachineSort11");
if (MachineSort==null)
{MachineSort="";
}
byte a[]=MachineSort.getBytes("ISO-8859-1");
MachineSort=new String(a);
if(MachineSort.equals("土石方工程机械"))
{ms="001";
}
if(MachineSort.equals("路面工程机械"))
{ms="002";
}
if(MachineSort.equals("混凝土及灰浆机械"))
{ms="003";
}
if(MachineSort.equals("水平运输机械"))
{ms="004";
}
if(MachineSort.equals("起重机垂直运输机械"))
{ms="005";
}
if(MachineSort.equals("打桩钻孔机械"))
{ms="006";
}
String MachineName=request.getParameter("MachineName11");
if (MachineName==null)
{MachineName="";
}
byte b[]=MachineName.getBytes("ISO-8859-1");
MachineName=new String(b);
if(MachineName.equals("推土机"))
{mn="001";
}
if(MachineName.equals("铲运机"))
{mn="002";
}
if(MachineName.equals("单斗挖掘机"))
{mn="003";
}
String InitValue=request.getParameter("InitValue");
if (InitValue==null)
{InitValue="";
}
String MachineNo=request.getParameter("MachineNo");
if (MachineNo==null)
{MachineNo="";
}
Connection con1=null;
Statement sql1=null;
ResultSet rs1=null;
try{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(ClassNotFoundException e){}
try{con1=DriverManager.getConnection("jdbc:microsoft:sqlserver://VIVI:1433;DatabaseName=qingyangRoad","sa","");
sql1=con1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String MachineID=ms+""+mn+""+MachineNo;
//String id="lab_ID";
//String name="labName";
//String sfz="labSfz";
//String age="labAge";
//String sex="labSex";
//String type="labType";
//String np="labNormalPrice";
//String rp="labRainPrice";
//String input="inputerID";
String condition1="INSERT INTO MaID VALUES"+"("+"'"+MachineSort+"','"+MachineName+"','"+MachineNo+"','"+MachineID+"','"+InitValue+"'"+")";
//String condition2="UPDATE labour SET labSfz = "+newlabSfz+" WHERE labName="+"'"+labName+"'";
//String condition3="UPDATE labour SET labAge = "+newlabAge+" WHERE labName="+"'"+labName+"'";
//String condition4="UPDATE labour SET labSex = "+newlabSex+" WHERE labName="+"'"+labName+"'";
//String condition5="UPDATE labour SET labType = "+newType+" WHERE labName="+"'"+labName+"'";
//String condition6="UPDATE labour SET labNormalPrice = "+newlabNormalPrice+" WHERE labName="+"'"+labName+"'";
//String condition7="UPDATE labour SET labRainPrice = "+newlabRainPrice+" WHERE labName="+"'"+labName+"'";
//String condition8="UPDATE labour SET inputerID = "+newinputerID+" WHERE labName="+"'"+labName+"'";
//执行更新操作。
sql1.executeUpdate(condition1);//执行添加操作。
//sql.executeUpdate(condition2);
//sql.executeUpdate(condition3);
//sql.executeUpdate(condition4);
//sql.executeUpdate(condition5);
//sql.executeUpdate(condition6);
//sql.executeUpdate(condition7);
//sql.executeUpdate(condition8);
//显示添加记录后表中的记录。
// con1.close();
}
catch(SQLException e)
{ }
%>
<% //获取提交的姓名。
// String lab_ID=request.getParameter("lab_ID");
//if (lab_ID==null)
//{lab_ID="";
// }
//byte b[]=name,getBytes("ISO-8859-1");
//name=new String(b);
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(ClassNotFoundException e){}
try{con=DriverManager.getConnection("jdbc:microsoft:sqlserver://VIVI:1433;DatabaseName=qingyangRoad","sa","");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String condition="SELECT * FROM MaID ORDER BY MachineID";
rs=sql.executeQuery(condition);
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"机械种类");
out.print("<TH width=100>"+"机械名称");
out.print("<TH width=50>"+"该类机械编号");
out.print("<TH width=50>"+"机械ID");
out.print("<TH width=50>"+"预值");
//out.print("<TH width=200>"+"工种");
//out.print("<TH width=100>"+"晴天工资");
//out.print("<TH width=100>"+"雨天工资");
//out.print("<TH width=100>"+"地址");
//out.print("<TH width=100>"+"备注");
//out.print("<TH width=100>"+"录入员ID");
//out.print("<TH width=100>"+"工人ID"); 需要时再用
out.print("</TR>");
while(rs.next())
{out.print("<TR>");
out.print("<TD>"+rs.getString("MachineSort")+"</TD>");
out.print("<TD>"+rs.getString("MachineName")+"</TD>");
out.print("<TD>"+rs.getString("MachineNo")+"</TD>");
out.print("<TD>"+rs.getString("MachineID")+"</TD>");
out.print("<TD>"+rs.getFloat("InitValue")+"</TD>");
//out.print("<TD>"+rs.getString("labType")+"</TD>");
//out.print("<TD>"+rs.getString("labNormalPrice")+"</TD>");
//out.print("<TD>"+rs.getString("labRainPrice")+"</TD>");
//out.print("<TD>"+rs.getString("labAdd")+"</TD>");
//out.print("<TD>"+rs.getString("labDemo")+"</TD>");
//out.print("<TD>"+rs.getString("inputerID")+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
con.close();
}
catch(SQLException e)
{ }
%>
</body>
</html>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
body,td,th {
color: #F7F7F7;
}
body {
background-color: #0099FF;
}
-->
</style></head><body>
<script Language="JavaScript">
function ChkFields() {
if (document.form1.MachineName11.value=='') {
window.alert ("请输入机械编号!")
document.form1.MachineName11.focus()
return false
}
if (document.form1.MachineNo.value=='') {
window.alert ("请输入机械编号!")
document.form1.MachineNo.focus()
return false
}
if (document.form1.InitValue.value=='') {
window.alert ("请输入预值!")
document.form1.InitValue.focus()
return false
}
return true
}
</script>
<p>您可以进行添加机械ID的操作:</p>
<form name="form1" method="post" action="" onsubmit="return ChkFields()">
<p>机械类别:
<select name="MachineSort11">
<Option value="土石方工程机械" selected>土石方工程机械
<Option value="路面工程机械">路面工程机械
<Option value="混凝土及灰浆机械">混凝土及灰浆机械
<Option value="水平运输机械">水平运输机械
<Option value="起重机垂直运输机械">起重机垂直运输机械
</select> <p>机械名称:
<select name="MachineName11">
<Option value="---">---土石方工程机械---
<Option value="推土机" selected>推土机
<Option value="铲运机">铲运机
<Option value="单斗挖掘机">单斗挖掘机
</select>
</p>
<p>机械的编号:
<input type="text" name="MachineNo">
</p>
<p>预值:
<input type="text" name="InitValue">
</p>
<p>
<input type="submit" name="Submit" value="添加">
</p>
</form>
<% //获取新的信息。
String ms="000";
String mn="000";
String MachineSort=request.getParameter("MachineSort11");
if (MachineSort==null)
{MachineSort="";
}
byte a[]=MachineSort.getBytes("ISO-8859-1");
MachineSort=new String(a);
if(MachineSort.equals("土石方工程机械"))
{ms="001";
}
if(MachineSort.equals("路面工程机械"))
{ms="002";
}
if(MachineSort.equals("混凝土及灰浆机械"))
{ms="003";
}
if(MachineSort.equals("水平运输机械"))
{ms="004";
}
if(MachineSort.equals("起重机垂直运输机械"))
{ms="005";
}
if(MachineSort.equals("打桩钻孔机械"))
{ms="006";
}
String MachineName=request.getParameter("MachineName11");
if (MachineName==null)
{MachineName="";
}
byte b[]=MachineName.getBytes("ISO-8859-1");
MachineName=new String(b);
if(MachineName.equals("推土机"))
{mn="001";
}
if(MachineName.equals("铲运机"))
{mn="002";
}
if(MachineName.equals("单斗挖掘机"))
{mn="003";
}
String InitValue=request.getParameter("InitValue");
if (InitValue==null)
{InitValue="";
}
String MachineNo=request.getParameter("MachineNo");
if (MachineNo==null)
{MachineNo="";
}
Connection con1=null;
Statement sql1=null;
ResultSet rs1=null;
try{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(ClassNotFoundException e){}
try{con1=DriverManager.getConnection("jdbc:microsoft:sqlserver://VIVI:1433;DatabaseName=qingyangRoad","sa","");
sql1=con1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String MachineID=ms+""+mn+""+MachineNo;
//String id="lab_ID";
//String name="labName";
//String sfz="labSfz";
//String age="labAge";
//String sex="labSex";
//String type="labType";
//String np="labNormalPrice";
//String rp="labRainPrice";
//String input="inputerID";
String condition1="INSERT INTO MaID VALUES"+"("+"'"+MachineSort+"','"+MachineName+"','"+MachineNo+"','"+MachineID+"','"+InitValue+"'"+")";
//String condition2="UPDATE labour SET labSfz = "+newlabSfz+" WHERE labName="+"'"+labName+"'";
//String condition3="UPDATE labour SET labAge = "+newlabAge+" WHERE labName="+"'"+labName+"'";
//String condition4="UPDATE labour SET labSex = "+newlabSex+" WHERE labName="+"'"+labName+"'";
//String condition5="UPDATE labour SET labType = "+newType+" WHERE labName="+"'"+labName+"'";
//String condition6="UPDATE labour SET labNormalPrice = "+newlabNormalPrice+" WHERE labName="+"'"+labName+"'";
//String condition7="UPDATE labour SET labRainPrice = "+newlabRainPrice+" WHERE labName="+"'"+labName+"'";
//String condition8="UPDATE labour SET inputerID = "+newinputerID+" WHERE labName="+"'"+labName+"'";
//执行更新操作。
sql1.executeUpdate(condition1);//执行添加操作。
//sql.executeUpdate(condition2);
//sql.executeUpdate(condition3);
//sql.executeUpdate(condition4);
//sql.executeUpdate(condition5);
//sql.executeUpdate(condition6);
//sql.executeUpdate(condition7);
//sql.executeUpdate(condition8);
//显示添加记录后表中的记录。
// con1.close();
}
catch(SQLException e)
{ }
%>
<% //获取提交的姓名。
// String lab_ID=request.getParameter("lab_ID");
//if (lab_ID==null)
//{lab_ID="";
// }
//byte b[]=name,getBytes("ISO-8859-1");
//name=new String(b);
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(ClassNotFoundException e){}
try{con=DriverManager.getConnection("jdbc:microsoft:sqlserver://VIVI:1433;DatabaseName=qingyangRoad","sa","");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String condition="SELECT * FROM MaID ORDER BY MachineID";
rs=sql.executeQuery(condition);
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"机械种类");
out.print("<TH width=100>"+"机械名称");
out.print("<TH width=50>"+"该类机械编号");
out.print("<TH width=50>"+"机械ID");
out.print("<TH width=50>"+"预值");
//out.print("<TH width=200>"+"工种");
//out.print("<TH width=100>"+"晴天工资");
//out.print("<TH width=100>"+"雨天工资");
//out.print("<TH width=100>"+"地址");
//out.print("<TH width=100>"+"备注");
//out.print("<TH width=100>"+"录入员ID");
//out.print("<TH width=100>"+"工人ID"); 需要时再用
out.print("</TR>");
while(rs.next())
{out.print("<TR>");
out.print("<TD>"+rs.getString("MachineSort")+"</TD>");
out.print("<TD>"+rs.getString("MachineName")+"</TD>");
out.print("<TD>"+rs.getString("MachineNo")+"</TD>");
out.print("<TD>"+rs.getString("MachineID")+"</TD>");
out.print("<TD>"+rs.getFloat("InitValue")+"</TD>");
//out.print("<TD>"+rs.getString("labType")+"</TD>");
//out.print("<TD>"+rs.getString("labNormalPrice")+"</TD>");
//out.print("<TD>"+rs.getString("labRainPrice")+"</TD>");
//out.print("<TD>"+rs.getString("labAdd")+"</TD>");
//out.print("<TD>"+rs.getString("labDemo")+"</TD>");
//out.print("<TD>"+rs.getString("inputerID")+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
con.close();
}
catch(SQLException e)
{ }
%>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货