}public int execUpdate(String sql) { int i=0; try { connect = DriverManager.getConnection(sConnStr,"scott","dingding"); Statement stmt = connect.createStatement(); i = stmt.executeUpdate(sql); } catch(SQLException ex) { System.err.println(ex.getMessage()); } return i; } }//news_post.jsp <%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*" errorPage="" %> <jsp:useBean id="ibmBean" scope="page" class="ibm.connibm"/> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=gb2312" /> <title>新闻模块</title> </head><body> <jsp:include page="/header.inc" flush="True" /> <jsp:include page="subject.inc" flush="True" /> <table width="780" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="600" height="20"><font color="#000000" size="2" >现在您的位置:新闻模块内容输入界面</font></td> <td width="180" height="20"><font color="#000000" size="2" >现在的时间是:xxxxxxxxxx</font></td> </tr> </table> <table width="780" border="0" cellspacing="0" cellpadding="0"> <% String vtitle,vfrom,vdate,vmessage,vauther; int vkinds;vtitle=request.getParameter("title"); vfrom=request.getParameter("from"); vdate=request.getParameter("date"); vmessage=request.getParameter("message"); vauther=request.getParameter("auther"); vkinds=request.getParameter("kinds"); String sql; ResultSet RS; sql="insert into chr_news(title,from,date,message,auther,kinds) values('"+vtitle+"','"+vfrom+"','"+vdate+"','"+"','"+vmessage+"','"+vauther+"',"+vkinds+")";//RS=ibmBean.executeQuery(sql); if(ibmBean.execUpdate(sql)!=0){ System.out.println("成功"); }%> 发送信件 </table><jsp:include page="/bottom.inc" flush="True" /> </body> </html>出现的错误提示type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPNo Java compiler was found to compile the generated source for the JSP. This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK to the common/lib directory of the Tomcat server, followed by a Tomcat restart. If using an alternate Java compiler, please check its installation and access path. org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:87) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:311) org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:378) org.apache.jasper.compiler.Compiler.compile(Compiler.java:421) org.apache.jasper.compiler.Compiler.compile(Compiler.java:402) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:512) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:262) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:263) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:210) javax.servlet.http.HttpServlet.service(HttpServlet.java:861) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:324) org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:246) java.security.AccessController.doPrivileged(Native Method) javax.security.auth.Subject.doAsPrivileged(Subject.java:500) org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:268) org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
chr_news的表结构; 名称 是否为空? 类型 ----------------------------------------- -------- ------------- TITLE NOT NULL VARCHAR2(40) FROM VARCHAR2(40) DATE VARCHAR2(10) MESSAGE NOT NULL VARCHAR2(2000 AUTHER NOT NULL VARCHAR2(10) KINDS NOT NULL NUMBER(1)另外,oracle自动提交在connibm.java中应怎么设置?
org.apache.jasper.JasperException: Unable to compile class for JSPNo Java compiler was found to compile the generated source for the JSP. This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK to the common/lib directory of the Tomcat server, followed by a Tomcat restart. If using an alternate Java compiler, please check its installation and access path.你的出错代码显示问题是因为无法找到JSP的编译器,提示你无法找到tools.jar这个文件。
//
RS=ibmBean.executeQuery(sql);插入语句,咋这么执行呢?
try to add commit to your program
public boolean update(String sql) throws Exception {
// 数据库连接在构造函数中生成(数据库连接可复用)
Statement stmt = connect.createStatement();
return (stmt.executeUpdate(sql)>0);
}然后将
RS=ibmBean.executeQuery(sql);
替换为:
if(ibmBean.update(sql)){
System.out.println("成功");
}
按照你的改了后,出现错误
javax.servlet.ServletException: ibm.connibm.update(Ljava/lang/String;)Z
是不是都是CHAR字段呢
插入的方法是executeUpdate(),并且插入方法返回的是一个int型的数值。表示影响的行数。所以应当:
public int executeQuery(String sql) {
int i=0;
try {
connect = DriverManager.getConnection(sConnStr,"scott","dingding");
Statement stmt = connect.createStatement();
i = stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return i;
}//在JSP页面,判断只要ibmBean.executeQuery(sql)!=0,则表示插入成功。
插入数据是用executeUpdate()
javax.servlet.ServletException: ibm.connibm.executeUpdate(Ljava/lang/String;)I
package ibm;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
import javax.naming.*;public class connibm {
String sDBDriver = "oracle.jdbc.driver.OracleDriver";
String sConnStr = "jdbc:oracle:thin:@ibm-2373-7wh:1521:ibm";
Connection connect = null;
ResultSet rs = null;
public connibm() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println( e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
connect = DriverManager.getConnection(sConnStr,"scott","dingding");
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}public int execUpdate(String sql) {
int i=0;
try {
connect = DriverManager.getConnection(sConnStr,"scott","dingding");
Statement stmt = connect.createStatement();
i = stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return i;
}
}//news_post.jsp
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean id="ibmBean" scope="page" class="ibm.connibm"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<title>新闻模块</title>
</head><body>
<jsp:include page="/header.inc" flush="True" />
<jsp:include page="subject.inc" flush="True" />
<table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="600" height="20"><font color="#000000" size="2" >现在您的位置:新闻模块内容输入界面</font></td>
<td width="180" height="20"><font color="#000000" size="2" >现在的时间是:xxxxxxxxxx</font></td>
</tr>
</table>
<table width="780" border="0" cellspacing="0" cellpadding="0">
<%
String vtitle,vfrom,vdate,vmessage,vauther;
int vkinds;vtitle=request.getParameter("title");
vfrom=request.getParameter("from");
vdate=request.getParameter("date");
vmessage=request.getParameter("message");
vauther=request.getParameter("auther");
vkinds=request.getParameter("kinds");
String sql;
ResultSet RS;
sql="insert into chr_news(title,from,date,message,auther,kinds) values('"+vtitle+"','"+vfrom+"','"+vdate+"','"+"','"+vmessage+"','"+vauther+"',"+vkinds+")";//RS=ibmBean.executeQuery(sql);
if(ibmBean.execUpdate(sql)!=0){
System.out.println("成功");
}%>
发送信件
</table><jsp:include page="/bottom.inc" flush="True" />
</body>
</html>出现的错误提示type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPNo Java compiler was found to compile the generated source for the JSP.
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path. org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:87)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:311)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:421)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:402)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:262)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:263)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:210)
javax.servlet.http.HttpServlet.service(HttpServlet.java:861)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:246)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:268)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
名称 是否为空? 类型
----------------------------------------- -------- -------------
TITLE NOT NULL VARCHAR2(40)
FROM VARCHAR2(40)
DATE VARCHAR2(10)
MESSAGE NOT NULL VARCHAR2(2000
AUTHER NOT NULL VARCHAR2(10)
KINDS NOT NULL NUMBER(1)另外,oracle自动提交在connibm.java中应怎么设置?
tools.jar在classpath已经设置public int execUpdate(String sql) {
int i=0;
try {
connect = DriverManager.getConnection(sConnStr,"scott","dingding");
Statement stmt = connect.createStatement();
i = stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return i;
}
还是有问题!//因为我把if(ibmBean.execUpdate(sql)!=0){
System.out.println("成功");
}
屏蔽掉/* */之后能够显示页面来.
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path.你的出错代码显示问题是因为无法找到JSP的编译器,提示你无法找到tools.jar这个文件。
System.out.println("成功");
}
*/
int i=0;
try {
connect = DriverManager.getConnection(sConnStr,"scott","dingding");
Statement stmt = connect.createStatement();
connect.setAutoCommit ( true ) ;
i = stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return i;
}
去掉/* */之后
if(ibmBean.execUpdate(sql)!=0){
System.out.println("成功");
}
能够显示页面,但是没有"成功",数据库里也没有新的数据
添加数据的时候是可以没有返回值的!!
public int execUpdate(String sql) {
int i=0;
try {
connect = DriverManager.getConnection(sConnStr,"scott","dingding");
Statement stmt = connect.createStatement();
i = stmt.executeUpdate(sql);
}
catch(Exception ex) {
System.out.println(ex.getMessage());
}
return i;
}
好象executeUpdate没有执行一样.
提交数据
关闭连接?
换直接插入数据也不能进入数据库.
是不是javabean还是有问题?请高手们能够指点迷津.配置:sun appserver 8.0,jdk1.4.2,oracle9i
[#|2004-09-04T21:30:21.130+0800|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.stream.out|_ThreadID=12;|
成功|#]在ORACLE里自动提交的功能是怎么设定的?