有关向数据库中添加一条记录的问题,JSP代码
如果添加数据库中已有的设备时,会提示此设备已添加,可是正确输入一条数据库中没有的信息时,总是显示“添加设备操作失败”提示,不知道哪出错了,用的是oracle9i数据库,请...
如果添加数据库中已有的设备时,会提示此设备已添加,可是正确输入一条数据库中没有的信息时,总是显示“添加设备操作失败”提示,不知道哪出错了,用的是oracle9i数据库,请高手指点,谢谢。
代码如下:
equi_add.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<html>
<head>
<title>添加设备</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.STYLE1 {font-family: "宋体"}
-->
</style>
</head>
<script language="javascript">
function mycheck(){
if (form1.EquiNo.value==""){
alert("请输入主设备号!");form1.EquiNo.focus();return;
}
if (form1.LabId.value==""){
alert("请输入实验台编号!");form1.LabId.focus();return;
}
if (form1.RoomId.value==""){
alert("请输入所属实验室!");form1.RoomId.focus();return;
}
if (form1.Charger.value==""){
alert("请输入设备负责人!");form1.Charger.focus();return;
}
if (form1.MacAddr.value==""){
alert("请输入MAC地址!");form1.MacAddr.focus();return;
}
if (form1.PowerAddr.value==""){
alert("请输入电源控制地址!");form1.PowerAddr.focus();return;
}
form1.submit();
}
</script>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="777" height="609" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableBorder_LTR">
<tr>
<td height="30" align="center" bgcolor="#eeeeee">≡≡≡添加设备≡≡≡</td>
</tr>
</table>
<table width="100%" height="396" border="0" cellpadding="0" cellspacing="0" class="tableBorder_LBR">
<tr>
<td width="10" height="395" valign="top"> </td>
<td width="767" valign="top"><table width="100%" height="56" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"> </td>
</tr>
<tr>
<td align="center">
<form action="equi_add_deal.jsp" method="post" name="form1">
<table width="100%" height="275" border="1" align="center" cellpadding="-2" cellspacing="-2" bordercolor="#66FFFF" bordercolordark="#FFFFFF">
<tr>
<td width="19%" height="27"> 主设备编号:</td>
由于字数限制,不能贴太多的代码,下面是我认为有可能出错的一段代码:
}else{
String sql="insert into lab_equi_table
(EquiNo,LabId,RoomId,Charger,MacAddr,PowerAddr,StatusFlag,AddFlag,Remark) values
('"+EquiNo+"','"+LabId+"','"+RoomId+"','"+Charger+"','"+MacAddr+"','"+PowerAddr+"',"+StatusF
lag+","+AddFlag+","+Remark+")";
int ret=0;
ret=Conndb.executeUpdate(sql);
if (ret!=0){
out.println("<script language='javascript'>alert('设备信息添加成
功!');window.location.href='index1.jsp';</script>");
}else{
out.println("<script language='javascript'>alert('设备信息添加失
败!');window.location.href='equi_add.jsp';</script>");
}
}
}else{
out.println("<script language='javascript'>alert('您的操作有
误!');window.location.href='index.jsp';</script>");
} 展开
代码如下:
equi_add.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<html>
<head>
<title>添加设备</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.STYLE1 {font-family: "宋体"}
-->
</style>
</head>
<script language="javascript">
function mycheck(){
if (form1.EquiNo.value==""){
alert("请输入主设备号!");form1.EquiNo.focus();return;
}
if (form1.LabId.value==""){
alert("请输入实验台编号!");form1.LabId.focus();return;
}
if (form1.RoomId.value==""){
alert("请输入所属实验室!");form1.RoomId.focus();return;
}
if (form1.Charger.value==""){
alert("请输入设备负责人!");form1.Charger.focus();return;
}
if (form1.MacAddr.value==""){
alert("请输入MAC地址!");form1.MacAddr.focus();return;
}
if (form1.PowerAddr.value==""){
alert("请输入电源控制地址!");form1.PowerAddr.focus();return;
}
form1.submit();
}
</script>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="777" height="609" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableBorder_LTR">
<tr>
<td height="30" align="center" bgcolor="#eeeeee">≡≡≡添加设备≡≡≡</td>
</tr>
</table>
<table width="100%" height="396" border="0" cellpadding="0" cellspacing="0" class="tableBorder_LBR">
<tr>
<td width="10" height="395" valign="top"> </td>
<td width="767" valign="top"><table width="100%" height="56" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"> </td>
</tr>
<tr>
<td align="center">
<form action="equi_add_deal.jsp" method="post" name="form1">
<table width="100%" height="275" border="1" align="center" cellpadding="-2" cellspacing="-2" bordercolor="#66FFFF" bordercolordark="#FFFFFF">
<tr>
<td width="19%" height="27"> 主设备编号:</td>
由于字数限制,不能贴太多的代码,下面是我认为有可能出错的一段代码:
}else{
String sql="insert into lab_equi_table
(EquiNo,LabId,RoomId,Charger,MacAddr,PowerAddr,StatusFlag,AddFlag,Remark) values
('"+EquiNo+"','"+LabId+"','"+RoomId+"','"+Charger+"','"+MacAddr+"','"+PowerAddr+"',"+StatusF
lag+","+AddFlag+","+Remark+")";
int ret=0;
ret=Conndb.executeUpdate(sql);
if (ret!=0){
out.println("<script language='javascript'>alert('设备信息添加成
功!');window.location.href='index1.jsp';</script>");
}else{
out.println("<script language='javascript'>alert('设备信息添加失
败!');window.location.href='equi_add.jsp';</script>");
}
}
}else{
out.println("<script language='javascript'>alert('您的操作有
误!');window.location.href='index.jsp';</script>");
} 展开
2个回答
展开全部
如果添加数据库中已有的设备时,会提示此设备已添加,可是正确输入一条数据库中没有的信息时,总是显示“添加设备操作失败”提示,不知道哪出错了,用的是oracle9i数据库,请高手指点,谢谢。
代码如下:
equi_add.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<html>
<head>
<title>添加设备</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.STYLE1 {font-family: "宋体"}
-->
</style>
</head>
<script language="javascript">
function mycheck(){
if (form1.EquiNo.value==""){
alert("请输入主设备号!");form1.EquiNo.focus();return;
}
if (form1.LabId.value==""){
alert("请输入实验台编号!");form1.LabId.focus();return;
}
if (form1.RoomId.value==""){
alert("请输入所属实验室!");form1.RoomId.focus();return;
}
if (form1.Charger.value==""){
alert("请输入设备负责人!");form1.Charger.focus();return;
}
if (form1.MacAddr.value==""){
alert("请输入MAC地址!");form1.MacAddr.focus();return;
}
if (form1.PowerAddr.value==""){
alert("请输入电源控制地址!");form1.PowerAddr.focus();return;
}
form1.submit();
}
</script>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="777" height="609" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableBorder_LTR">
<tr>
<td height="30" align="center" bgcolor="#eeeeee">≡≡≡添加设备≡≡≡</td>
</tr>
</table>
<table width="100%" height="396" border="0" cellpadding="0" cellspacing="0" class="tableBorder_LBR">
<tr>
<td width="10" height="395" valign="top"> </td>
<td width="767" valign="top"><table width="100%" height="56" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"> </td>
</tr>
<tr>
<td align="center">
<form action="equi_add_deal.jsp" method="post" name="form1">
<table width="100%" height="275" border="1" align="center" cellpadding="-2" cellspacing="-2" bordercolor="#66FFFF" bordercolordark="#FFFFFF">
<tr>
<td width="19%" height="27"> 主设备编号:</td>
问题补充:由于字数限制,不能贴太多的代码,下面是我认为有可能出错的一段代码:
}else{
String sql="insert into lab_equi_table
(EquiNo,LabId,RoomId,Charger,MacAddr,PowerAddr,StatusFlag,AddFlag,Remark) values
('"+EquiNo+"','"+LabId+"','"+RoomId+"','"+Charger+"','"+MacAddr+"','"+PowerAddr+"',"+StatusF
lag+","+AddFlag+","+Remark+")";
int ret=0;
ret=Conndb.executeUpdate(sql);
if (ret!=0){
out.println("<script language='javascript'>alert('设备信息添加成
功!');window.location.href='index1.jsp';</script>");
}else{
out.println("<script language='javascript'>alert('设备信息添加失
败!');window.location.href='equi_add.jsp';</script>");
}
}
}else{
out.println("<script language='javascript'>alert('您的操作有
误!');window.location.href='index.jsp';</script>");
}
就好了。
代码如下:
equi_add.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<html>
<head>
<title>添加设备</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.STYLE1 {font-family: "宋体"}
-->
</style>
</head>
<script language="javascript">
function mycheck(){
if (form1.EquiNo.value==""){
alert("请输入主设备号!");form1.EquiNo.focus();return;
}
if (form1.LabId.value==""){
alert("请输入实验台编号!");form1.LabId.focus();return;
}
if (form1.RoomId.value==""){
alert("请输入所属实验室!");form1.RoomId.focus();return;
}
if (form1.Charger.value==""){
alert("请输入设备负责人!");form1.Charger.focus();return;
}
if (form1.MacAddr.value==""){
alert("请输入MAC地址!");form1.MacAddr.focus();return;
}
if (form1.PowerAddr.value==""){
alert("请输入电源控制地址!");form1.PowerAddr.focus();return;
}
form1.submit();
}
</script>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="777" height="609" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableBorder_LTR">
<tr>
<td height="30" align="center" bgcolor="#eeeeee">≡≡≡添加设备≡≡≡</td>
</tr>
</table>
<table width="100%" height="396" border="0" cellpadding="0" cellspacing="0" class="tableBorder_LBR">
<tr>
<td width="10" height="395" valign="top"> </td>
<td width="767" valign="top"><table width="100%" height="56" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"> </td>
</tr>
<tr>
<td align="center">
<form action="equi_add_deal.jsp" method="post" name="form1">
<table width="100%" height="275" border="1" align="center" cellpadding="-2" cellspacing="-2" bordercolor="#66FFFF" bordercolordark="#FFFFFF">
<tr>
<td width="19%" height="27"> 主设备编号:</td>
问题补充:由于字数限制,不能贴太多的代码,下面是我认为有可能出错的一段代码:
}else{
String sql="insert into lab_equi_table
(EquiNo,LabId,RoomId,Charger,MacAddr,PowerAddr,StatusFlag,AddFlag,Remark) values
('"+EquiNo+"','"+LabId+"','"+RoomId+"','"+Charger+"','"+MacAddr+"','"+PowerAddr+"',"+StatusF
lag+","+AddFlag+","+Remark+")";
int ret=0;
ret=Conndb.executeUpdate(sql);
if (ret!=0){
out.println("<script language='javascript'>alert('设备信息添加成
功!');window.location.href='index1.jsp';</script>");
}else{
out.println("<script language='javascript'>alert('设备信息添加失
败!');window.location.href='equi_add.jsp';</script>");
}
}
}else{
out.println("<script language='javascript'>alert('您的操作有
误!');window.location.href='index.jsp';</script>");
}
就好了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Wb4
{
public static void main(String ags[])
{
int a[] = new int[100];
a[0] = 1;
a[1] = 2;
int n;
for(n = 2; n < 100; n ++)
{
a[n] = a[n - 1] + a[n - 2];
System.out.print(a[n]+" ");
}
if(n % 10 == 0)
{
System.out.println("");
}
}
}
{
public static void main(String ags[])
{
int a[] = new int[100];
a[0] = 1;
a[1] = 2;
int n;
for(n = 2; n < 100; n ++)
{
a[n] = a[n - 1] + a[n - 2];
System.out.print(a[n]+" ");
}
if(n % 10 == 0)
{
System.out.println("");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询