我想在从 jsp 文件输入的数据库中输入数据,但不知道如何连接它们。有人可以建议我连接这两个文件并添加以 jsp 形式输入的数据吗?
这是我的jsp和java文件...
test1.java
package P1;
import java.sql.*;
class test1 {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Connection con = null;
try {
Class.forName("oracle.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex) {
System.out.println("Error: unable to load driver class!");
System.exit(1);
}
con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.106.87:1521:ORA11G","fuel_db","foel");
Statement statement = con.createStatement();
String command = "INSERT INTO student (name, rollno, class, mobileno) VALUES (?, ?, ?, ?);";
statement.executeUpdate(command);
con.close();
}
}
test1.html
**
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>FORM</title>
<script type="text/javascript">
<%
String name = request.getParameter("name");
String roll = document.getElementById("rollno");
String clas = document.getElementById("class");
String mobile = document.getElementById("mobileno");
test1 myTest = new test1();
myTest.submitData();
%>
function getvalues()
{
var name = document.getElementById("name");
var roll = document.getElementById("rollno");
var clas = document.getElementById("class");
var mobile = document.getElementById("mobileno");
}
function num(e)
{
var k;
document.all ? k = e.keyCode : k = e.which;
return (!((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8));
}
</script>
</head>
<body>
<form action="test1.java" method="post" >
<table>
<tr>
<td>First Name: </td>
<td><input type="text" name="name" maxlength="10"></td>
</tr>
<tr>
<td>roll:</td>
<td><input type="text" name="rollno" maxlength="5" onkeypress="return num(event)"></td>
</tr>
<tr>
<td>class:</td>
<td><input type="text" name="class" maxlength="10"></td>
</tr>
<tr>
<td>Mobile:</td>
<td><input type="text" name="mobileno" maxlength="10" onkeypress="return num(event)"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" onclick="getvalues()"></td>
</tr>
</table>
</form>
</body>
</html>
**