<%@ page language="java" import="java.util.*"%>
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'adduser.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
<form method="POST" action="adduser.jsp">
<p>
请输入增加的信息
</p>
<table>
<tr>
<td>
用户名
</td>
<td>
<input type="text" name="username">
</td>
</tr>
<tr>
<td>
密码
</td>
<td>
<input type="text" name="password">
</td>
</tr>
</table>
<table><tr><td><input type="submit" value="提交">
<input type="reset" value="重置"></td></tr>
<tr><td>查看记录</td></tr>
</table>
</form>
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
String url="jdbc:oracle:thin:@localhost:1521:myoracle";
String user = "scott";
String pass = "tiger";
out.print("1<br>");
Connection con=DriverManager.getConnection(url,user,pass);
Statement sql ;
sql = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String strSQL;
strSQL = "INSERT INTO text a values( " +
request.getParameter("'username'") + "," +
request.getParameter("'password'") +")";
out.print("2<br>");
out.print("3<br>");
sql.executeUpdate(strSQL);out.print("3<br>");
out.print("2<br>");
ResultSet rs = sql.executeQuery("SELECT * FROM text"); //执行SQL语句
out.print("3");
while (rs.next())
{out.print("<table><TR ><td>用户名</td><TD>");
rs.getString("dusername");
out.print("</TD><td>密码</td><TD>");
rs.getString("dpassword");
out.print("</TD></TR></table>");}
}
catch(Exception e)
{}
%>
</body>
</html>执行结果
请输入增加的信息 用户名
密码
查看记录 1
2
3
无法执行 sql.executeUpdate(strSQL);
跪求速回
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'adduser.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
<form method="POST" action="adduser.jsp">
<p>
请输入增加的信息
</p>
<table>
<tr>
<td>
用户名
</td>
<td>
<input type="text" name="username">
</td>
</tr>
<tr>
<td>
密码
</td>
<td>
<input type="text" name="password">
</td>
</tr>
</table>
<table><tr><td><input type="submit" value="提交">
<input type="reset" value="重置"></td></tr>
<tr><td>查看记录</td></tr>
</table>
</form>
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
String url="jdbc:oracle:thin:@localhost:1521:myoracle";
String user = "scott";
String pass = "tiger";
out.print("1<br>");
Connection con=DriverManager.getConnection(url,user,pass);
Statement sql ;
sql = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String strSQL;
strSQL = "INSERT INTO text a values( " +
request.getParameter("'username'") + "," +
request.getParameter("'password'") +")";
out.print("2<br>");
out.print("3<br>");
sql.executeUpdate(strSQL);out.print("3<br>");
out.print("2<br>");
ResultSet rs = sql.executeQuery("SELECT * FROM text"); //执行SQL语句
out.print("3");
while (rs.next())
{out.print("<table><TR ><td>用户名</td><TD>");
rs.getString("dusername");
out.print("</TD><td>密码</td><TD>");
rs.getString("dpassword");
out.print("</TD></TR></table>");}
}
catch(Exception e)
{}
%>
</body>
</html>执行结果
请输入增加的信息 用户名
密码
查看记录 1
2
3
无法执行 sql.executeUpdate(strSQL);
跪求速回
out.println(strSQL);
request.getParameter("'username'") + "," +
request.getParameter("'password'") +")";
request.getParameter("'username'") + "," +
request.getParameter("'password'") +")"; a是什么,是列吗?不要写列名,要不然就把列明写全