发帖    主题    评论    推荐    标签    作者    订阅    查搜    注册   登陆   关注
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 大数据 扩展性 并发编程 事件驱动 分布式 SOA

数据怎么插不进去(数据库)?

2006-08-04 18:22
赞助商链接

代码:
<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<%!
public String CodeToString(String str)
{
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>

<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@210.43.2.209:1521:oemrep","system","admin");

PreparedStatement pstmt = conn.prepareStatement("insert into faculty values(?,?,?,?,?)");
int FacultyID=Integer.parseInt((String)request.getParameter("FacultyID")) ;
String Name = (String)request.getParameter("Name") ;
int RoomID=Integer.parseInt((String)request.getParameter("RoomID")) ;
String Phone = (String)request.getParameter("Phone") ;
int DepID=Integer.parseInt((String)request.getParameter("DepID")) ;
pstmt.setInt(1,FacultyID);
pstmt.setString(2,"Name");
pstmt.setInt(3,RoomID);
pstmt.setString(4,"Phone");
pstmt.setInt(5,DepID);
pstmt.executeUpdate();
pstmt.close();
conn.close();
}
catch(Exception e)
{
//System.out.println(request.getParameter("RoomID"));
System.out.println(e);
}
%>
<head>
<title>数据插入</title>
</head>
<body>
<center>
<table border="1" width="700">
<tr>
<td height="24"><div align="center">数据插入程序</div></td>
</tr>
<tr>
<td height="24">数据插入成功!</td>
</tr>
</table>
</center>
</html>

出现的错误:
在页面输入字母出现: java.lang.NumberFormatException: For in put String: ""
输入数字:java.sql.SQLException: ORA-017222: 无效数字

2006-08-04 18:23

中间代码:

return s;
}
}
%>

<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@210.43.2.209:1521:oemrep","system","admin");

PreparedStatement pstmt = conn.prepareStatement("insert into faculty values(?,?,?,?,?)");
int FacultyID=Integer.parseInt((String)request.getParameter("FacultyID")) ;
String Name = (String)request.getParameter("Name") ;
int RoomID=Integer.parseInt((String)request.getParameter("RoomID")) ;
String Phone = (String)request.getParameter("Phone") ;
int DepID=Integer.parseInt((String)request.getParameter("DepID")) ;
pstmt.setInt(1,FacultyID);
pstmt.setString(2,"Name");
pstmt.setInt(3,RoomID);
pstmt.setString(4,"Phone");
pstmt.setInt(5,DepID);
pstmt.executeUpdate();
pstmt.close();
conn.close();
}
catch(Exception e)
{
//System.out.println(request.getParameter("RoomID"));
System.out.println(e);
}

出现的错误:
在页面输入字母出现: java.lang.NumberFormatException: For in put String: ""
输入数字:java.sql.SQLException: ORA-017222: 无效数字

2006-08-04 18:26

输入数据的页面:

<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<head>
<title>输入数据</title>
</head>
<body>
<form action="insertT2.jsp"method="post" name="from1">
<table width="591" height="237" border="1" align="center" >
<tr>
<td width="133" height="35">FacultyID:</td>
<td width="442"><input type="text" name="FacultyID"size="60" /></td>
</tr>
<tr>
<td height="31">Name:</td>
<td><input type="text" name="Name" size="60"/></td>
</tr>
<tr>
<td height="31">RoomID:</td>
<td><input type="text" name="RoomID"size="60" /></td>
</tr>
<tr>
<td height="31">Phone:</td>
<td><input type="text" name="Phone" size="60"/></td>
</tr>
<tr>
<td height="31">DepID:</td>
<td><input type="text" name="DepID"size="60" /></td>
</tr>
<tr>
<td height="31" colspan="2">
<div align="center">
<input type="submit" value="提交">
<input type="reset" value="重输">
</div></td>
</tr>
</table>
</form>
</body>
</html>

2006-08-05 16:38

是不是与数据库定义的数据类型冲突,或插入的数据有非法字符

赞助商链接

赞助商链接

返回顶部

移动版 关于本站 使用帮助 联系管理员 最佳分辨率1366x768
OpenSource JIVEJDON Powered by JdonFramework Code © 2002-20 jdon.com