0

我有这部分代码

try
 {
  Connection conn=new DBconnect().con();
   Statement stmt=new DBconnect().stm(conn);
   //Statement stmt2=new DBconnect().stm(conn);
   ResultSet rs = stmt.executeQuery( "UPDATE bill SET     REMAIND_FREE_TIME="+FreeTimeN+"WHERE telephone="+tel);
// ResultSet rs2 = stmt2.executeQuery(" UPDATE bill SET REMAIND_FREE_TIME="+FreeTimeN2+"WHERE telephone="+tel2);

问题是,每当我使用一个更新运行它时,一切都很好,但是当我同时运行它们时会出错。这是数据库类:

package database_console;

 import frames.login;
import java.sql.*;

public class DBconnect {
Statement stmt;
ResultSet rs;
Connection conn;

public Connection con() throws ClassNotFoundException, SQLException{
Class.forName( "oracle.jdbc.OracleDriver" ) ;

    // Get a connection to the database
    conn = DriverManager.getConnection( "jdbc:oracle:thin:@83.212.240.15:1521:orcl","it21119", "a37161637" ) ;
    return conn;
}

public Statement stm(Connection conn) throws SQLException {
    // Get a statement from the connection
   stmt = conn.createStatement() ;
return stmt;
}


public void stop(Connection conn,Statement stmt, ResultSet rs) throws SQLException{

    rs.close() ;
  stmt.close() ;
  conn.close() ;
 }
}

有什么建议吗?提前谢谢。(顺便说一句,我正在使用带有 ojdbc6.jar 的 sqldeveloper)

4

1 回答 1

0

唯一的问题可能是您传递的参数不是数据库中的 Varchar2 列。

更好地使用PreparedStatement和设置参数。检查此链接以获取详细信息PreparedStatementhttp ://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html

于 2013-06-08T14:10:00.443 回答