MCA最后一年的项目问题 [英] MCA final year project problem
本文介绍了MCA最后一年的项目问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jsp和oracle中的项目.我的问题是,当我通过html表单插入数据时,数据将插入数据库中,但是每当我尝试插入字符串数据时,它仅采用整数值,则数据库不会更新.请帮我...我在下面插入了代码...
jsp代码
newbra1.jsp
My project in jsp and oracle. My problem is that when I insert the data through html form then data is inseted in database but it takes only integer values whenever I try to insert string data then database is not updated. plz help me... I inserted code below...
jsp code
newbra1.jsp
<html>
<body background="background.jpg">
<%@page import="java.sql.*" %>
<%@page import="java.io.*" %>
<%@page import="java.lang.*"%>
<%
try
{
String p1=request.getParameter("t1");
String p2=request.getParameter("t2");
String p3=request.getParameter("t3");
String p4=request.getParameter("t4");
String p5=request.getParameter("t5");
String p6=request.getParameter("t6");
String p7=request.getParameter("t7");
String p8=request.getParameter("t8");
int p9=Integer.parseInt(request.getParameter("t9"));
String p10=request.getParameter("t10");
String p11=request.getParameter("t11");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:admin","scott1","tiger1");
java.sql.Statement pst1=con.createStatement();
// PreparedStatement pst1=null;
//String q1="insert into branch_details values(?,?,?,?)";
// String q2="insert into employee_details values(?,?,?,?,?,?,?)";
//String q3="insert into employee_login values(?,?,?,?)";
//String q4="insert into employee_map values(?,?,?)";
// pst1=con.prepareStatement(q1);
/* pst1.setString(1,p1);
pst1.setString(2,p2);
pst1.setString(3,p3);
pst1.setString(4,p4);*/
pst1.executeUpdate("insert into branch_details values('"+p1+"','"+p2+"','"+p3+"','"+p4+"')");
/*
PreparedStatement pst2=null;
pst2=con.prepareStatement(q2);
pst2.setString(1,p2);
pst2.setString(2,p1);
pst2.setString(3,p7);
pst2.setString(4,p6);
pst2.setString(5,p8);
pst2.setInt(6,p9);
pst2.setString(7,p10);
pst2.executeUpdate();
PreparedStatement pst3=null;
pst3=con.prepareStatement(q3);
pst3.setString(1,p2);
pst3.setString(2,p7);
pst3.setString(3,p5);
pst3.setString(4,p6);
pst3.executeUpdate();
PreparedStatement pst4=null;
pst4=con.prepareStatement(q4);
pst4.setString(1,p2);
pst4.setString(2,p6);
pst4.setString(3,p11);
pst4.executeUpdate();*/
con.commit();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<br>
<br><br>
<center>
<h4>Branch Details Stored</center></h4>
<br><br><br><br>
<center>
</body>
</html>
HTML程式码:
newbra.html
Html code:
newbra.html
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY bgColor=turquoise>
<form action="newbra1.jsp" method="post">
<P> <FONT
color=blue><STRONG> ADD
NEW BRANCH PM AND
BM </STRONG></FONT></P>
<P> </P>
<TABLE border=0 cellPadding=1 cellSpacing=1
style="HEIGHT: 119px; LEFT: 96px; POSITION: absolute; TOP: 45px; WIDTH: 292px; Z-INDEX: 100"
width="75%">
<TR>
<TD><FONT color=blue>BRANCH ID</FONT></TD>
<TD><FONT color=blue><INPUT id=text1 name="t1"></FONT></TD></TR>
<TR>
<TD><FONT color=blue>USER ID</FONT></TD>
<TD><FONT color=blue><INPUT id=text2 name="t2"></FONT></TD></TR>
<TR>
<TD><FONT color=blue>BRANCH NAME</FONT></TD>
<TD><FONT color=blue><INPUT id=text3 name="t3"></FONT></TD></TR>
<TR>
<TD><FONT color=blue>BRANCH ADD</FONT></TD>
<TD><INPUT id=text4 name="t4"></TD></TR>
<TR>
<TD><FONT color=#0000ff>PASSWORD</FONT></TD>
<TD><INPUT id=text4 name="t5"></TD></TR>
<TR>
<TD><FONT color=#0000ff>DESIGNATION</FONT></TD>
<TD><INPUT id=text4 name="t6"></TD></TR>
<TR>
<TD><FONT color=#0000ff>UNAME</FONT></TD>
<TD><INPUT id=text4 name="t7"></TD></TR>
<TR>
<TD><FONT color=#0000ff>UADDRESS</FONT></TD>
<TD><INPUT id=text4 name="t8"></TD></TR>
<TR>
<TD><FONT color=#0000ff>UPHONENO</FONT></TD>
<TD><INPUT id=text4 name="t9"></TD></TR>
<TR>
<TD><FONT color=#0000ff>UEMAIL</FONT></TD>
<TD><INPUT id=text4 name="t10"></TD></TR>
<TR>
<TD><FONT color=#0000ff>USERBOSSID</FONT></TD>
<TD><INPUT id=text4 name="t11"></TD></TR>
</TABLE>
<P><INPUT id=submit1 name=submit1 style="HEIGHT: 24px; LEFT: 232px; POSITION: absolute; TOP: 400px; WIDTH: 67px; Z-INDEX: 101" type=submit value=Submit><INPUT id=reset1 name=reset1 style="HEIGHT: 24px; LEFT: 318px; POSITION: absolute; TOP: 399px; WIDTH: 58px; Z-INDEX: 102" type=reset value=Reset> </P>
<form>
</BODY>
</HTML>
推荐答案
为自己-和每个需要阅读此书的人-请为变量使用明确定义的名称.这根本无法维护!
为什么一个TextField的名称为"t1",一个String的名称为"p1",另一个为"q1"?称它为"tfBranchID","strBranchID"和"strQueryBranchID"-清晰无误!当所有变量开始看起来相同时,很容易迷路...
您的问题:数据库在该特定位置是否期望使用String?似乎您使用的是不同的表格-您是否寻址正确的表格?并查看您的查询,然后再在数据库上触发它们.system.print.out();
很简单,对您有很大帮助.
问候
Torsten
for yourself - and every person who needs to read this - please use clear defined names for variables. This is not maintainable at all!
Why has a TextField the name "t1", a String the name "p1" and another one "q1"? call it something like "tfBranchID", "strBranchID" and "strQueryBranchID" - that''s clear and unmistakable! It''s easy to get lost when all the variables start looking the same...
to your question: is the database expecting a String at that particular position? It seems like you''re using different tables - do you address the right table? and take a look at your queries before you fire them on the db. asystem.print.out();
is simple and helps a lot.
regards
Torsten
这篇关于MCA最后一年的项目问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文