以下两个查询分别返回大约十条记录。
package com.guycarp.fac.casualty.ejb.copyFacAccount;
import javax.ejb.*;
import weblogic.ejb.*;
import com.guycarp.common.gcerror.GCException;
import java.rmi.RemoteException;
import java.sql.*;
import javax.ejb.*;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.transaction.UserTransaction;
import java.math.BigDecimal;
import com.guycarp.fac.casualty.facManager.*;
import com.guycarp.fac.casualty.ejb.company.EBCompany.*;
import com.guycarp.common.util.*;
import com.guycarp.fac.casualty.util.*;
/**
* @ejbgen:session enable-call-by-reference="true" default-transaction="Supports"
* ejb-name = "SBCopyFacAccount"
*
* @ejbgen:jndi-name local="ejb.SBCopyFacAccountLocalHome"
* remote = "ejb.SBCopyFacAccountRemoteHome"
*
* @ejbgen:file-generation remote-class = "true" remote-class-name="SBCopyFacAccountRemote" remote-home = "true" remote-home-name="SBCopyFacAccountRemoteHome" local-class="true" local-class-name="SBCopyFacAccount" local-home="true" local-home-name="SBCopyFacAccountHome"
*/
public class SBCopyFacAccountBean
extends GenericSessionBean
implements SessionBean
{
public void ejbCreate() {
// Your code here
}
private SessionContext m_ctx = null;
protected final String SBCOPY_JDBC_URL = "COPYACCOUNT_JDBC_URL";
protected final String CLASS_NAME = "com.guycarp.fac.casualty.ejb.copyFacAccount.SBCopyFacAccountBean";
private EBCompanyHome m_EBCompanyHome = null;
/**
* @ejbgen:local-method
* @ejbgen:remote-method
*/
public String copyAccount(String p_OldCedantCompany, String p_OldFacAccountNumber , Double p_OldFacAccountVersion,
String p_NewCedantCompany, String p_UserId,
BigDecimal idSubmission,Boolean isCedant,String lines, String renewal) throws GCException
{
Connection conn = null;
CallableStatement cs = null;
//UserTransaction utx = null;
String newFacAccountNumber=null;
try {
conn = getConnection();
/** Using the new procedure for getUID which has an OUTPUT Parameter.
*/
//utx = m_ctx.getUserTransaction();
//utx.begin();
//System.out.println("lines " + lines);
cs = conn.prepareCall("{call procCopyFacAccount(?, ?, ?, ?, ?, ?, ?, ?, ?,"+lines+",?,?,?)}");
//System.out.println("p_OldCedantCompany " + p_OldCedantCompany);
cs.setString(1,p_OldCedantCompany);
//System.out.println("p_OldFacAccountNumber " + p_OldFacAccountNumber);
cs.setString(2,p_OldFacAccountNumber);
//System.out.println("p_OldFacAccountVersion " + p_OldFacAccountVersion);
cs.setDouble(3,p_OldFacAccountVersion.doubleValue());
//System.out.println("p_NewCedantCompany " + p_NewCedantCompany);
cs.setString(4,p_NewCedantCompany);
cs.setString(5,"FacExchange");
cs.setString(6,"SBCopyFacAccount");
//System.out.println("p_UserId " + p_UserId);
cs.setString(7,p_UserId);
//System.out.println("idSubmission " + idSubmission);
cs.setBigDecimal(8,idSubmission);
if (isCedant != null) {
//System.out.println("cedant");
if (isCedant.booleanValue()) {
//System.out.println("cedant true");
cs.setInt(9,1);
} else {
//System.out.println("cedant false");
cs.setInt(9,0);
}
}
cs.setString(10,renewal);
cs.registerOutParameter(11,java.sql.Types.VARCHAR);
cs.registerOutParameter(12,java.sql.Types.VARCHAR);
boolean b = cs.execute(); //HRH 2002-08-19 : Unused local variable
int i = cs.getUpdateCount();// HRH 2002-08-19 : Unused local variable
String ErrorMessage = cs.getString(11);
//System.out.println("ErrorMessage= " + ErrorMessage);
newFacAccountNumber = cs.getString(12);
//System.out.println("SBCopyFacAccountBean newFacAccountNumber " + newFacAccountNumber);
if ( ErrorMessage != null && !ErrorMessage.equals("") ) {
throw new GCException( new Exception(ErrorMessage), ErrorMessage, false, false);
}
//utx.commit();
//utx = null;
} catch ( Exception e ) {
GCUtility.errorInfo(e.getMessage());
throw new GCException( e, "Exception thrown in copyAccount.", false, false);
} finally {
/*
if ( utx!= null ) {
try {
utx.rollback();
} catch ( Exception e ) {
e.printStackTrace();
throw new GCException( e, "Exception thrown in copyAccount.", false, false);
}
}
*/
try {
if ( cs != null ) cs.close();
if ( conn != null ) conn.close();
} catch ( Exception e ) {
GCUtility.errorInfo(e.getMessage());
throw new GCException( e, "Exception thrown in copyAccount.", false, false);
}
}
//before sending this newFacAccountNumber back, set the optprimary for this account as 1.
if (newFacAccountNumber != null) {
newFacAccountNumber= newFacAccountNumber.trim();
String accountNumber = p_OldCedantCompany + " " + newFacAccountNumber + " " + FacConstant.FACACCOUNTVERSION_01;
Connection con = null;
PreparedStatement stmt= null;
try {
String sql = "UPDATE TBLFACACCOUNT SET OPTACCOUNTPRIMARY = 1 WHERE CDEFACACCOUNTNUMBER="+newFacAccountNumber
+" and UIDCEDANTCOMPANY = "+getEBCompany(p_NewCedantCompany) +" and NUMFACACCOUNTVERSION="+FacConstant.FACACCOUNTVERSION_01;
con = getConnection();
stmt = con.prepareStatement(sql);
int success = stmt.executeUpdate();
} catch (Exception e) {
GCUtility.errorInfo("Exception in copy account bean"+e.getMessage());
}
}
return newFacAccountNumber ;
}
/**
* @ejbgen:local-method
* @ejbgen:remote-method
*/
public void copyAccount(BigDecimal idSubmission, String newCedantCompany,
String userId) throws GCException {
Connection conn = null;
CallableStatement cs = null;
//UserTransaction utx = null;
try {
conn = getConnection();
/** Using the new procedure for getUID which has an OUTPUT Parameter.
*/
//utx = m_ctx.getUserTransaction();
//utx.begin();
cs = conn.prepareCall("{call procCopyFacAccountsSubmission(?, ?, ?, ?, ?)}");
cs.setDouble(1,idSubmission.doubleValue());
cs.setString(2,newCedantCompany);
cs.setString(3,"FacExchange");
cs.setString(4,"SBCopyFacAccountBean");
cs.setString(5,userId);
cs.registerOutParameter(6,java.sql.Types.VARCHAR);
boolean b = cs.execute();
int i = cs.getUpdateCount();
String ErrorMessage = cs.getString(6);
if ( ErrorMessage != null && !ErrorMessage.equals("") ) {
throw new GCException( new Exception(ErrorMessage), ErrorMessage, false, false);
}
//utx.commit();
//utx = null;
} catch ( Exception e ) {
GCUtility.errorInfo(e.getMessage());
throw new GCException( e, "Exception thrown in copyAccount of "+ CLASS_NAME, false, false);
} finally {
/*
if ( utx!= null ) {
try {
utx.rollback();
} catch ( Exception e ) {
e.printStackTrace();
throw new GCException( e, "Exception while rolling back in copyAccount of "+ CLASS_NAME, false, false);
}
}
*/
try {
if ( cs != null ) cs.close();
if ( conn != null ) conn.close();
} catch ( Exception e ) {
GCUtility.errorInfo(e.getMessage());
throw new GCException( e, "Exception while closing connection in copyAccount of "+ CLASS_NAME, false, false);
}
}
}
private Double getEBCompany(String cdeCompanyNumber) throws GCException{
Double uidCompany = null;
// @@ uncomment this line when eb is ready
//
try {
EBCompanyHome m_EBCompanyHome = (EBCompanyHome)GCHomesCache.getHome(EBCompanyHome.class,FacConstant.EBCOMPANY_JNDI_URL);
EBCompany ebCompany = m_EBCompanyHome.findByCompanyNumber(cdeCompanyNumber);
if (ebCompany != null) {
// @@ line changed
//uidCompany = ebCompany.getID();
uidCompany = new Double(ebCompany.getM_uidCompany().doubleValue());
}
return uidCompany;
} catch (ObjectNotFoundException e) {
return null;
} catch(Exception e) {
throw new GCException (e,"Exception in getEBCompany(String cdeCompanyNumber) of copy account process",false,false);
}
//
}
protected Connection getConnection() throws Exception {
InitialContext ic = new InitialContext();
DataSource dataSource = (DataSource) ic.lookup("jdbc.FacExchangeDS");
return dataSource.getConnection();
}
}
但是,当我同时运行两个查询时
SELECT ACC_NO
FROM TABLE1
WHERE ACC_NO IN (1, 2, 3, 4, 5)
AND DATE = 300618
SELECT ACC_NO
FROM TABLE1
WHERE ACC_NO IN (1, 2, 3, 4, 5)
AND DATE = 310718
它返回数十万条记录。怎么会这样?
答案 0 :(得分:1)
使用IN
SELECT ACC_NO
FROM TABLE1
WHERE ACC_NO IN (1, 2, 3, 4, 5)
AND DATE in ( 300618, 310718)
答案 1 :(得分:0)
如果将OR
与AND
一起使用,则需要使用括号:
SELECT ACC_NO
FROM TABLE1
WHERE ACC_NO IN (1, 2, 3, 4, 5) AND (DATE = 300618 OR DATE = 310718);
但是,如果您有更多的日期,这很奇怪,因此请使用IN
子句,而不要使用大的OR
s:
SELECT ACC_NO
FROM TABLE1
WHERE ACC_NO IN (1, 2, 3, 4, 5) AND DATE IN (300618, 310718);