我使用简单的 JSP 代码将 5 个字段插入到我的 oracle 10g 数据库中。在提交表单时,我收到一个异常“jdbc.odbc.JdbcOdbcDriver”。我无法理解问题所在。请帮帮我。我的代码如下:
注册.html
<html>
<head><title>Sign up</title>
<link rel="stylesheet" type="text/css" href="default.css">
<link rel="stylesheet" type="text/css" href="align.css">
<script language="javascript">
function validation(Form_obj)
{
if(Form_obj.fnametxt.value.length==0)
{
alert("Please, fill up the first name!!!");
Form_obj.fnametxt.focus();
return false;
}
if(Form_obj.lnametxt.value.length==0)
{
alert("Please, fill up the last name!!!");
Form_obj.lnametxt.focus();
return false;
}
if(Form_obj.usrnametxt.value.length==0)
{
alert("Please, fill up the user name!!!");
Form_obj.usrnametxt.focus();
return false;
}
if(Form_obj.pswdtxt.value.length==0)
{
alert("Please, fill up the password name!!!");
Form_obj.pswdtxt.focus();
return false;
}
if(Form_obj.phonetxt.value.length==0)
{
alert("Please, fill up the phone number!!!");
Form_obj.phonetxt.focus();
return false;
}
return true;
}
</script>
</head>
<a href="index.html"><h1>Jobs Portal</h1></a>
<div id="sign">Sign up</div>
<center>
<form id="form" action="signup.jsp" method="post" name="signform" onSubmit="return validation(this)">
<table border="3" cellpadding="0" cellspacing="0">
<tr><td>
<table>
<tr><td colspan="2" align="center">Fill your details</td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td>First Name</td><td><input type="text" name="fnametxt"></td></tr>
<tr><td>Last Name</td><td><input type="text" name="lnametxt"></td></tr>
<tr><td>User Name</td><td><input type="text" name="usrnametxt"></td></tr>
<tr><td>Password</td><td><input type="password" name="pswdtxt"></td></tr>
<tr><td>Mobile no.</td><td><input type="text" name="phonetxt"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="signbt" value="Sign up" > </td></tr>
</td></tr>
</table>
</form>
</center>
</html>
注册.jsp
<%@page language="java" import="java.sql.*"%>
<%@page import="java.io.*"%>
<%
try
{
ResultSet rs=null;
Class.forName("jdbc.odbc.JdbcOdbcDriver");
Connection con= DriverManager.getConnection("jdbc:oracle:jobsportal","abdus","jbaat");
Statement stmt=con.createStatement();
String fname=request.getParameter("fnametxt");
String lname=request.getParameter("lnametxt");
String usrname=request.getParameter("usrnametxt");
String pswd=request.getParameter("pswdtxt");
String phone=request.getParameter("phonetxt");
stmt.executeUpdate("insert into jobs(fname,lname,username,password,phone) values('"+fname+"','"+lname+"','"+usrname+"','"+pswd+"','"+phone+"'");
rs=stmt.executeQuery("select * from jobs");
%>
<html>
<head><title>Sign up Successful</title>
<link rel="stylesheet" type="text/css" href="default.css">
</head>
Your details</br>
<table border="0">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>User Name</th>
<th>Password</th>
<th>Phone number</th>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td><%=rs.getString("fname")%></td>
<td><%=rs.getString("lname")%></td>
<td><%=rs.getString("username")%></td>
<td><%=rs.getString("password")%></td>
<td><%=rs.getString("phone")%></td>
</tr>
<% rs.close();
}}
catch(ClassNotFoundException e)
{
out.println(e.getMessage());
} %>
</table>
</html>