当前位置: 技术问答>java相关
为什么我用javabean更新不了数据库?javabean,oracle高手请进!!!!!高分相赠!!!在线等待中。。。
来源: 互联网 发布时间:2017-03-12
本文导语: 环境win2k+tomcat4.1 程序执行不出错,但就是添加不到数据库里 javabean源代码: package firm; import java.sql.*; public class firm { String sDBDriver = "oracle.jdbc.driver.OracleDriver"; String sConnStr = "jdbc:oracle:thin:@localhost:1521:or...
环境win2k+tomcat4.1
程序执行不出错,但就是添加不到数据库里
javabean源代码:
package firm;
import java.sql.*;
public class firm {
String sDBDriver = "oracle.jdbc.driver.OracleDriver";
String sConnStr = "jdbc:oracle:thin:@localhost:1521:oradb";
String sUser = "system";
String sPws = "manager";
String sql = "" ;
private Connection conn = null;
private Statement stmt = null;
ResultSet rs = null;
public firm() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("firm(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr,sUser,sPws);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql) {
stmt = null;
rs=null;
try {
conn = DriverManager.getConnection(sConnStr,sUser,sPws);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
}
public void closeRs(){
try{
rs.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public void closeStmt(){
try{
stmt.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try{
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
jap调用程序源代码
留言写入数据库
程序执行不出错,但就是添加不到数据库里
javabean源代码:
package firm;
import java.sql.*;
public class firm {
String sDBDriver = "oracle.jdbc.driver.OracleDriver";
String sConnStr = "jdbc:oracle:thin:@localhost:1521:oradb";
String sUser = "system";
String sPws = "manager";
String sql = "" ;
private Connection conn = null;
private Statement stmt = null;
ResultSet rs = null;
public firm() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("firm(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr,sUser,sPws);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql) {
stmt = null;
rs=null;
try {
conn = DriverManager.getConnection(sConnStr,sUser,sPws);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
}
public void closeRs(){
try{
rs.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public void closeStmt(){
try{
stmt.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try{
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
jap调用程序源代码
留言写入数据库
|
你也可以看看tomcat的日志(logs/catalinaout)的最后几行,看有没有错误提示,或者直接把你的sql语句放到sqlplus里面执行,看有没有错误。
|
你把生成的sql语句放在数据库环境里执行,看看结果,这样起码可以找到是哪里出错的。
|
你以前好象贴过类试的贴子。
关于批量更新,我记不清了。
好象是
addBean.executeUpdate(strSQL);
下面还要有一行代码确定执行
关于批量更新,我记不清了。
好象是
addBean.executeUpdate(strSQL);
下面还要有一行代码确定执行