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

06-08-04 angelia
代码:

<%@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: 无效数字

angelia
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: 无效数字

angelia
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>

qqq1981
2006-08-05 16:38
是不是与数据库定义的数据类型冲突,或插入的数据有非法字符

猜你喜欢