Oracle and empty strings
Hi All,
i'm porting my application to Oracle and i'm experiencing (big) issues since empty strings are treated as null by Oracle.
This is a big issue for me since my application uses empty and null values as two different things (indeed they are different !!), ie, i'm not having null pointer exception, but wrong behavior.
I'm thinking what's the best approach to follow since my appl. must work also on mysql and postgres.
Three options at the moment:
1. implement a jdbc wrapper that converts any empty string in something like '~'.
2. using aspectj, add some aspects to setString/getString converting any empty string in something like '~'.
3. buy a commercial driver that makes difference between empty and null (using aforementioned approaches ?).
I think that this difference in Oracle is really an impediment in doing applications db neutral and I'd like to ask your opinion about the best solution (if someone already resolved it as i guess).
Does anyone know if there are commercial jdbc driver that can help me ?
Does anyone know how ORM frameworks (like hibernate) handle this case ?
Thanks in advance
ste
jschell wrote:
nichele wrote:
jwenting wrote:
If NULL really is different in your context from an empty string you're going to have to define some sequence of characters as indicating an empty string.yes, this is what i need to implement.Sounds like a flawed design then.
I'm wondering what's the best approach in order to avoid to change all my application isolating this behavior somewhere (wrapping the jdbc driver for instance).That doesn't make much sense to me. You should already have a database layer. You change the database layer. If you don't have a database layer then that means you have another design flaw. And in that case I would really not be the one that needs to maintain that code base.I thought a bit about the value of your answer...but i didn't find it ....sorry but i don't like who replies on forum just to say bad design/bad choice etc...if you have any kind of suggestion you are welcome, otherwise you can spend your time in doing something else instead of reply to this thread.
Similar Messages
-
Null and empty string not being the same in object?
Hello,
I know that null and empty string are interpreted the same in oracle.
However I discovered the strange behaviour concerning user defined objects:
create or replace
TYPE object AS OBJECT (
value VARCHAR2(2000)
declare
xml xmltype;
obj object;
begin
obj := object('abcd');
xml := xmltype(obj);
dbms_output.put_line(xml.getStringVal());
obj.value := '';
xml := xmltype(obj);
dbms_output.put_line(xml.getStringVal());
obj.value := null;
xml := xmltype(obj);
dbms_output.put_line(xml.getStringVal());
end;
When creating xml from object, all not-null fields are transformed into xml tag.
I supposed that obj.value being either '' or null will lead to the same result.
However this is output from Oracle 9i:
<OBJECT_ID><VALUE>abcd</VALUE></OBJECT_ID>
<OBJECT_ID><VALUE></VALUE></OBJECT_ID>
<OBJECT_ID/>
Oracle 10g behaves as expected:
<OBJECT><VALUE>abcd</VALUE></OBJECT>
<OBJECT/>
<OBJECT/>
However Oracle 9i behaviour leads me to the conclusion that oracle
must somehow distinguish between empty string and null in user defined objects...
Can someone clarify this behaviour?
Thus is it possible to test if object's field is empty or null?However Oracle 9i behaviour leads me to the conclusion that oracle
must somehow distinguish between empty string and null in user defined objects...
Can someone clarify this behaviour?
Thus is it possible to test if object's field is empty or null?A lot of "fixes" were done, relating to XML in 10g and the XML functionality of 9i was known to be buggy.
I think you can safely assume that null and empty strings are treated the same by Oracle regardless. If you're using anything less than 10g, it's not supported any more anyway, so upgrade. Don't rely on any assumptions that may appear due to bugs. -
Oracle SQL-92 Non compliance: When will oracle support empty strings?
Oracle is the only database on the planet that equates an empty string to a null value. For several major versions, Oracle has said "Make sure you don't rely on null and empty string equivalency because it could go away in the future." When will Oracle get with it and support this aspect of the SQL-92 standard (not to mention mathmatical logic)?
You log enhancement requests through Metalink.
The procedure is documented in Metalink document 166650.1 as follows:
How to Log an Enhancement Request:
Create a new Service Request in MetaLink.
On the Create a SR - Brief Description screen, in the Type of problem field, select Enhancement Request.
Important factors to remember when filling out the Enhancement Request Service Request template and creating the Service Request:
Fully describe why the current product functionality does not meet your needs.
Explain in detail the enhancement you would like implemented
If possible, describe how the product can be changed to achieve the desired results.
Describe your business expectations. Include key milestone dates and justifications as to why this request is so important and the benefits your organization stands to gain should this request be accepted.
Once your Service Request has been created, it will be assigned to a Support Engineer who will validate your information. In some cases, your request may be a new or known product defect that the Support Engineer can either provide a fix, a workaround, or introduce to Oracle Development for resolution. In other cases, you may be presenting a valuable product enhancement that can improve Oracle product functionality. In all cases, the Support Engineer will be able to qualify your request and pass along the information to Oracle Development.
Once the Support Engineer validates your request, and an agreed upon action plan is created, your Support Engineer will create a new Enhancement Request and provide you with an Enhancement Request tracking number. The BUG search tool on MetaLink can then be used to receive status updates.
Please note that the Support Engineer will close the SR once the enhancement has been logged.
Also, see document 214168.1 -
VARCHAR2:: How to differnciate between NULL and empty string '' ?
Hello to all,
I'm looking for a possibility to differnciate between NULL and empty string '' in column of type VARCHAR2.
I have an application relying on that there is a difference between NULL and ''.
Is it possible to configure ORACLE in some way ?
Thanx in advance,
Thomastry check if a varchar variable has an empty string
by checking its lengthAnd that would accomplish what? But see for yourself:
DECLARE
v_test VARCHAR2(10);
BEGIN
v_test := '';
DBMS_OUTPUT.put_line(LENGTH(v_test));
v_test := NULL;
DBMS_OUTPUT.put_line(LENGTH(v_test));
END; C. -
ORACLE treats empty Strings as NULL, Any workaround?
Hi,
ORACLE treats empty Strings as NULL.
I am writing, rather modifying Java code to make it work with both SQLServer and Oracle. Since our code is already working for SQLServer, now I have the problem in porting to Oracle wherever I have empty strings. I used to insert empty strings into coulumns in SQLServers, the same SQLs give errors in SQL Server.
Any workaround on the DB end or in JDBC for this?
Thanks in advance,
Suresh
[email protected]jschell wrote:
nichele wrote:
jwenting wrote:
If NULL really is different in your context from an empty string you're going to have to define some sequence of characters as indicating an empty string.yes, this is what i need to implement.Sounds like a flawed design then.
I'm wondering what's the best approach in order to avoid to change all my application isolating this behavior somewhere (wrapping the jdbc driver for instance).That doesn't make much sense to me. You should already have a database layer. You change the database layer. If you don't have a database layer then that means you have another design flaw. And in that case I would really not be the one that needs to maintain that code base.I thought a bit about the value of your answer...but i didn't find it ....sorry but i don't like who replies on forum just to say bad design/bad choice etc...if you have any kind of suggestion you are welcome, otherwise you can spend your time in doing something else instead of reply to this thread. -
Difference in Null and Empty String
Hi,
I have been wondering about the difference between Null and Empty String in Java. So I wrote a small program like this:
public class CompareEmptyAndNullString {
public static void main(String args[]) {
String sNull = null;
String sEmpty = "";
try {
if (sNull.equalsIgnoreCase(sEmpty)) {
System.out.println("Null and Empty Strings are Equal");
} else {
System.out.println("Null and Empty Strings are Equal");
} catch (Exception e) {
e.printStackTrace();
This program throws Exception: java.lang.NullPointerException
at practice.programs.CompareEmptyAndNullString.main(CompareEmptyAndNullString.java:10)
Now if I change the IF Clause to if (sEmpty.equalsIgnoreCase(sNull)) then the Program outputs this: Null and Empty Strings are Equal
Can anyone explain why this would happen ?
Thanks in Advance !!JavaProwler wrote:
Saish,
Whether you do any of the following code, the JUnit Test always passes: I mean he NOT Sign doesnt make a difference ...
assert (! "".equals(null));
assert ("".equals(null));
You probably have assertions turned off. Note the the assert keyword has nothing to do with JUnit tests.
I think that older versions of JUnit, before assert was a language keyword (which started in 1.4 or 1.5), had a method called assert. Thus, if you have old-style JUnit tests, they might still compile, but the behavior is completely different from what it was in JUnit, and has nothing to do with JUnit at all.
If you turn assertions on (-ea flag in the JVM command line, I think), the second one will throw AssertionError. -
What is difference between Null String and Empty String ?
Hi
Just i have little confusion that the difference bet'n NULL String and Empty String ..
Please clear my doubte.
ThankxFor the same reason I think it's okay to say "null
String" and "empty String "as long as you know they
really mean "null String reference" and "empty String
object" respectively. Crap. It's only okay to say that as long as *the one you're talking to" knows what it really means. Whether you know it or not is absolutely irrelevant. And there is hardly any ambiguity about the effects that a statement like "assign an object to a reference" brings. "Null String" differs in that way. -
What is the difference between String Constant and Empty String Constant
What is the difference between string constant which does not contain any value and the Empty string constant?
While testing a VI which contain a normal string constant in VI analyzer, it gives error to change string constant with the empty string constant?
Please Reply
prabhakant
Regards
Prabhakant PatilReadability.
Functionally, they are the same. From a coding standpoint, the Empty String Constant is unambiguous.
It is empty and will always be; good for initialization. Also, because you can not type a value into and Empty String Constant, someone would need to conciously replace it to set a 'default' value that is something other than NULL.
Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.
"You are what you don't automate"
Inplaceness is synonymous with insidiousness -
Oracle, Null and empty Strings
Currently I'm facing problems with a class, which contains a String, which
is set to "" (empty String).
When the class is persistent, oracle writes null to the table column
(which seems to be common oracle behaviour) and when retrieving the class,
the field is set to null as well, giving me a lot of null-pointer
exceptions.
Anyway ... I can cope with that (just a lot of extra work)
far worse is the problem, wenn searching objects, that have this field set
to "" oder null.
Oracle can't find the records because JDO creates Querys "where
string=null" or "where string=''" , where oracle expects "where string is
null" to find the records.
Is there a workaround or solution ?Yeah, that would work as well, thx, but since I have to cope with
null-Strings now everywhere in my program, it doesn't hurt just to forbid
empty strings on the program side.
In future times I'll test on Oracle first, then porting to DB/2 - this way
I suppose work is far less to garant compability.
Nevertheless ... having to set the bankcode into quotes is a kodo bug in
my opinion.
Kodo knows the type of classfields (in this case string) and shouldn't
send the parameter as a BigDecimal to the database.
Given that, and having only bankcodes of null (only neccesary when using
Oracle), the method would look like:
public Collection getAccounts (String bankCode)
throws Exception
return getAccounts (Account.class, "bankcode=="+bankcode);
which is how a transparent persistent layer, um, should be , um , I mean
... just transparent ;-D
Marc Prud'hommeaux wrote:
Stefan-
Couldn't you just do something like:
public Collection getAccounts (String bankCode)
throws Exception
String filter;
if (bankCode == null || bankCode.length () == 0)
filter = "(bankCode == null || bankCode == "")";
else
filter = "bankCode == "" + bankCode + """;
return getAccounts (Account.class, filter);
If I understand the problem correctly, this should work for all the
databases.
In article <[email protected]>, Stefan wrote:
What operations are you performing to cause this SQL to be issued? You
say you are having trouble removing objects, but this is clearly not a
DELETE statement. Is this the SQL that is issued when looking up
objects by identity?I'm not removing objects, I was removing just quotes from parameters ;-)
A string column... is it also represented as a string field in your class?Yeah ... just to give you an impression of the code:
First we have a class, representing a bank account:
public class Account {
private AccountMgr myAccountMgr;
private String bankCode;
private String id;
Note, that in nearly all cases bankCode will be a number or null.
I have a second class "AccountMgr", which does all of the persistant stuff
(seaching, making persistent etc.)
This class has two methods, one versatile (protected) to retrieve accounts
by a given filterString and one who just returns accounts by bankCode,
building the expected filterstring. Here is my current working version:
public class AccountMgr {
public Collection getAccounts(String bankCode) throws Exception {
if (bankCode!=null) {
if (bankCode.equals("")) {
throw new Exception("check code, bankCode='' not allowed to get
same behavior from DB2 and Oracle");
// if set, quote the bankCode
bankCode="""+bankCode+""";
return getAccounts(Account.class,"bankCode=="+bankCode);
protected Collection getAccounts(Class accountClass, String filterAdd)
throws Exception {
PersistenceManager pm = MyHelper.getPersistenceManager();
String filter="";
if (filterAdd!=null && !filterAdd.trim().equals("")) {
filter+=filterAdd + " && ";
filter += "myAccountMgr==_accMgr";
Query query = pm.newQuery(accountClass, filter);
query.declareParameters("AccountMgr _accMgr");
return (Collection) query.execute(this);
As you can see, in the first method I have to set the bankCode into
quotes, when it's not null.
This is because otherwise a filter like "bankCode=1234" will be translated
in a way, where 1234 is send as a BigDecimal to the database:
[...] executing statement <4239745>: (SELECT [...] FROM JDO_ACCOUNT t0
WHERE t0.BANKCODE = ? : [reused=1;params={(BigDecimal) 1234}]
Marc Prud'hommeaux [email protected]
SolarMetric Inc. http://www.solarmetric.com -
Hi There,
As far as I know, Null is not the same as an empty string; however, when I try this out, I get some unexpected results (well, at least unexpected for my liking):
SQL> CREATE TABLE TS (MID NUMBER,
2 MDESC VARCHAR2(20) DEFAULT '' NOT NULL);
Table created.
SQL> INSERT INTO TS VALUES(1,'');
INSERT INTO TS VALUES(1,'')
ERROR at line 1:
ORA-01400: cannot insert NULL into ("TT"."TS"."MDESC")So, according to the above scenario, I can't insert an empty string!! However, an empty string is a valid string that doesn't have tuples/data!!
How come Oracle translates the null string '' as NULL?
ThanksWilliam Robertson wrote:
There is a special case to do with CHAR values, whereby '' counts as a string and so gets blank-padded, whereas NULL does not.Are you referring to:
SQL> DECLARE
2 flag CHAR(2);
3 PROCEDURE check_null (p_flag IN CHAR)
4 IS
5 BEGIN
6 IF p_flag = ' '
7 THEN
8 dbms_output.put_line ('flag is equal to '' ''');
9 ELSIF p_flag IS NULL
10 THEN
11 dbms_output.put_line ('flag is null');
12 ELSE
13 dbms_output.put_line ('other');
14 END IF;
15 END;
16 BEGIN
17 flag := '';
18 check_null (flag);
19 flag := NULL;
20 check_null (flag);
21 end;
22 /
flag is equal to ' '
flag is null
PL/SQL procedure successfully completed.
SQL> alter session set events '10932 trace name context forever, level 16384';
Session altered.
SQL> DECLARE
2 flag CHAR(2);
3 PROCEDURE check_null (p_flag IN CHAR)
4 IS
5 BEGIN
6 IF p_flag = ' '
7 THEN
8 dbms_output.put_line ('flag is equal to '' ''');
9 ELSIF p_flag IS NULL
10 THEN
11 dbms_output.put_line ('flag is null');
12 ELSE
13 dbms_output.put_line ('other');
14 END IF;
15 END;
16 BEGIN
17 flag := '';
18 check_null (flag);
19 flag := NULL;
20 check_null (flag);
21 end;
22 /
flag is null
flag is null
PL/SQL procedure successfully completed.
SQL> SY.
P.S. Don't ask me why normal (or at least consistent) behavior is not the default. -
More Fun with NULLs and Empty Strings
Greetings,
I ran across this behavior recently and thought I'd share with the forum. I'm running 10.2.0.2. Note the difference in behavior between passing and explicit NULL in the parameter vice passing an empty string (''):
CREATE OR REPLACE PROCEDURE NULL_ES_TEST(PARAM1 IN VARCHAR2) IS
VAR1 CHAR(1);
BEGIN
IF PARAM1 IS NULL THEN
DBMS_OUTPUT.PUT_LINE('PARAM1 IS NULL');
END IF;
VAR1 := PARAM1;
IF VAR1 IS NULL THEN
DBMS_OUTPUT.PUT_LINE('VAR1 IS NULL');
ELSE
DBMS_OUTPUT.PUT_LINE('VAR1 IS NOT NULL');
END IF;
DBMS_OUTPUT.PUT_LINE('THE LENGTH OF VAR1 IS '||TO_CHAR(LENGTH(VAR1)));
END NULL_ES_TEST;
EXEC NULL_ES_TEST(PARAM1 => '');
PARAM1 IS NULL
VAR1 IS NOT NULL
THE LENGTH OF VAR1 IS 1
(var1 now holds a single space)
EXEC NULL_ES_TEST(PARAM1 => NULL);
PARAM1 IS NULL
VAR1 IS NULL
THE LENGTH OF VAR1 IS
Any Comments or Insights are welcome.
Sincerely,
Dale WardWell somethings not as expected (tested on 10.2.0.3)
Even if you default the parameter to '', it treats null and '' differently.
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE PROCEDURE NULL_ES_TEST(PARAM1 IN VARCHAR2 := '') IS
2 VAR1 CHAR(1);
3 BEGIN
4 IF PARAM1 IS NULL THEN
5 DBMS_OUTPUT.PUT_LINE('PARAM1 IS NULL');
6 END IF;
7 VAR1 := PARAM1;
8 IF VAR1 IS NULL THEN
9 DBMS_OUTPUT.PUT_LINE('VAR1 IS NULL');
10 ELSE
11 DBMS_OUTPUT.PUT_LINE('VAR1 IS NOT NULL');
12 END IF;
13 DBMS_OUTPUT.PUT_LINE('THE LENGTH OF VAR1 IS '||TO_CHAR(LENGTH(VAR1)));
14* END NULL_ES_TEST;
SQL> /
Procedure created.
SQL> exec null_es_test(null);
PARAM1 IS NULL
VAR1 IS NULL
THE LENGTH OF VAR1 IS
PL/SQL procedure successfully completed.
SQL> exec null_es_test('');
PARAM1 IS NULL
VAR1 IS NOT NULL
THE LENGTH OF VAR1 IS 1
PL/SQL procedure successfully completed.
SQL> -
Difference between null string and empty string??
what is the major difference between null string and an empty string??
I wrote the following simple program and I could see some different output.
Other than that, any other differences that we should pay attention to???
C:\>java TestCode
Hello
nullHello
public class TestCode
public static void main(String[] s)
{ String s1 = "";
String s2 = null;
System.out.println(s1 + "Hello");
System.out.println(s2 + "Hello");
}The difference is that an empty String is just empty but a null String has no value (i.e. it is not instantiated) this has signifigance since all Strings are objects.
-
StringTokenizer vs. split and empty strings -- some clarification please?
Hi everybody,
I posted a question that was sort of similar to this once, asking if it was best to convert any StringTokenizers to calls to split when parsing strings, but this one is a little different. I rarely use split, because if there are consecutive delimiters, it gives empty strings in the array it returns, which I don't want. On the other hand, I know StringTokenizer is slower, but it doesn't give empty strings with consecutive delimiters. I would use split much more often if there was a way to use it and not have to check every array element to make sure it isn't the empty string. I think I may have misunderstood the javadoc to some extent--could anyone explain to me why split causes empty strings and StringTokenizer doesn't?
Thanks,
Jezzica85Because they are different?
Tokenizers are designed to return tokens, whereas split is simply splitting the String up into bits. They have different purposes
and uses to be honest. I believe the results of previous discussions of this have indicated that Tokenizers are slightly (very
slightly and not really meaningfully) faster and tokenizers do have the option of return delimiters as well which can be useful
and is a functionality not present in just a straight split.
However. split and regex in general are newer additions to the Java platform and they do have some advantages. The most
obvious being that you cannot use a tokenizer to split up values where the delimiter is multiple characters and you can with
split.
So in general the advice given to you was good, because split gives you more flexibility down the road. If you don't want
the empty strings then yes just read them and throw them away.
Edited by: cotton.m on Mar 6, 2008 7:34 AM
goddamned stupid forum formatting -
How to distinguish NULL and Empty Strings
Hi,
Just to set the context right; I'm an experienced C programmer trying labview for the first time. As such I ran in to a problem being that Labview has no concept of NULL-pointers and more specifically appears to have no concept of the difference between a NULL-string and an empty-string
I'm trying to make a structure (bundle) of strings (in it's most basic form key-value pairs) which i'd like to (for instance) URI encode in order to send it to a web server. For those who are not familiar with URI encoding; there is a distinguished difference between setting a key to an empty string and setting a key with no value. In C I would use a pointer to an empty string vs a NULL string pointer to symbolize this.
In essence I need an elegant way to distinguish between a defined but empty string and an undefined string (hmmm this is actually describing the same problem but now in terms of perl).
Anybody have any pointers (pun not intended) for me ?This is a bit depending on the interface you have with your encoder. The whole issue is that LV has no pointers at all (and you will like it, as you will never have any Null-Pointer exeptions and the like).
Assuming that you use a dll (so the Call Library node).
Use CString as input -> NULL-Terminated String.
Use I32 as input and pass 0 -> NULL string.
Felix
www.aescusoft.de
My latest community nugget on producer/consumer design
My current blog: A journey through uml -
PreparedStatement and empty String instead of space
Hi all, I would test a space value in a varchar field, i.e.:
PreparedStatement ps=con.prepareStatement();
String qry = "select a from table where b=? and c=?";
ps.setString(1,"value");
ps.setString(2," "); // space!!
That source code doesn't work: it set "" (empty String) in the second field, not " " (space).
Can I use PrepareStatement in any way to do this or I have to use only Statement?
Thanks.
Bye.my friend, the question was: how do you know the
parameter is set to "" (empty string)?I don't know: I suppose!!! because it's the only reason for that it returns no record. I tested my query in this three ways:
1) directly in sqlplus: SELECT OCCFASE As fase, OCLCVVC as convRat, SUM(QTA1) As qta1UM, SUM(QTA2) As qta2UM
FROM DJITMPRE WHERE OCCFASE IN ('I','P') AND OCCCOSC='XXXXX' AND OCCITEM='RUG-02' AND OCCTPVR = 'RUG'
AND OCCVAR1 = '01' AND OCCVAR2 = 'WW' AND OCCVAR3 = '12' AND OCCTPIM = '01' AND MAGAZZINO = 'MAG03'
AND COMMESSA = ' ' AND ORIG = ' ' AND PARTITA = ' ' AND CONFIG = 0.0 AND VANO = ' '
GROUP BY OCCFASE, OCLCVVC
and it returns one record.
2) using Statement:
Statement s = conn.createStatement();
String societa=session.getCompanyLogisticName(DSession.TABLE_LOGISTIC);
StringBuffer qry=new StringBuffer();
StringBuffer whereClause=new StringBuffer();
qry.append("SELECT OCCFASE As fase, OCLCVVC as convRat, SUM(QTA1) As qta1UM, SUM(QTA2) As qta2UM ");
qry.append("FROM DJITMPRE ");
qry.append("WHERE OCCFASE IN ('I','P') ");
qry.append("AND OCCCOSC='");
qry.append(societa);
qry.append("' ");
whereClause.append("AND OCCITEM='");
whereClause.append(b.getItemCode());
whereClause.append("' ");
whereClause.append("AND OCCTPVR = '");
if (b.getVariantType().equals("")){
whereClause.append(EscapeString.getLengthString(b.getVariantType(), 1));
}else{
whereClause.append(b.getVariantType());
whereClause.append("' ");
whereClause.append("AND OCCVAR1 = '");
if (b.getFirstVariant().equals("")){
whereClause.append(EscapeString.getLengthString(b.getFirstVariant(), 1));
}else{
whereClause.append(b.getFirstVariant());
whereClause.append("' ");
whereClause.append("AND OCCVAR2 = '");
if (b.getSecondVariant().equals("")){
whereClause.append(EscapeString.getLengthString(b.getSecondVariant(), 1));
}else{
whereClause.append(b.getSecondVariant());
whereClause.append("' ");
whereClause.append("AND OCCVAR3 = '");
if (b.getThirdVariant().equals("")){
whereClause.append(EscapeString.getLengthString(b.getThirdVariant(), 1));
}else{
whereClause.append(b.getThirdVariant());
whereClause.append("' ");
whereClause.append("AND OCCTPIM = '");
if (b.getPackingType().equals("")){
whereClause.append(EscapeString.getLengthString(b.getPackingType(), 1));
}else{
whereClause.append(b.getPackingType());
whereClause.append("' ");
whereClause.append("AND MAGAZZINO = '");
if (b.getWarehouseCode().equals("")){
whereClause.append(EscapeString.getLengthString(b.getWarehouseCode(), 1));
}else{
whereClause.append(b.getWarehouseCode());
whereClause.append("' ");
whereClause.append("AND COMMESSA = '");
if (b.getProjectItem().equals("")){
whereClause.append(EscapeString.getLengthString(b.getProjectItem(), 1));
}else{
whereClause.append(b.getProjectItem());
whereClause.append("' ");
whereClause.append("AND ORIG = '");
if (b.getSourceLot().equals("")){
whereClause.append(EscapeString.getLengthString(b.getSourceLot(), 1));
}else{
whereClause.append(b.getSourceLot());
whereClause.append("' ");
whereClause.append("AND PARTITA = '");
if (b.getLotNumber().equals("")){
whereClause.append(EscapeString.getLengthString(b.getLotNumber(), 1));
}else{
whereClause.append(b.getLotNumber());
whereClause.append("' ");
whereClause.append("AND CONFIG = ");
whereClause.append(b.getItemConfiguration());
whereClause.append("AND VANO = '");
if (b.getLocation().equals("")){
whereClause.append(EscapeString.getLengthString(b.getLocation(), 1));
}else{
whereClause.append(b.getLocation());
whereClause.append("' ");
qry.append(whereClause.toString());
qry.append(" GROUP BY OCCFASE, OCLCVVC");
ResultSet rs = s.executeQuery(qry.toString());
and it returns one record.
3) using PreparedStatement:
StringBuffer qry=new StringBuffer();
qry.append("SELECT OCCFASE As fase, OCLCVVC as convRat, SUM(QTA1) As qta1UM, SUM(QTA2) As qta2UM ");
qry.append("FROM DJITMPRE WHERE OCCFASE IN ('I','P') ");
qry.append("AND OCCCOSC='").append(societa).append("' ");
qry.append("AND OCCITEM=? AND OCCTPVR = ? ");
qry.append("AND OCCVAR1 = ? AND OCCVAR2 = ? AND OCCVAR3 = ? ");
qry.append("AND OCCTPIM = ? AND MAGAZZINO = ? AND COMMESSA = ? ");
qry.append("AND ORIG = ? AND PARTITA = ? AND CONFIG = ? ");
qry.append("AND VANO = ? ");
qry.append("GROUP BY OCCFASE, OCLCVVC");
PreparedStatement bookedQtyPS = conn.prepareStatement(qry.toString());
bookedQtyPS.setString(1,b.getItemCode());
if (b.getVariantType().equals("")){
bookedQtyPS.setString(2,EscapeString.getLengthString(b.getVariantType(), 1));
}else{
bookedQtyPS.setString(2,b.getVariantType());
if (b.getFirstVariant().equals("")){
bookedQtyPS.setString(3,EscapeString.getLengthString(b.getFirstVariant(), 1));
}else{
bookedQtyPS.setString(3,b.getFirstVariant());
if (b.getSecondVariant().equals("")){
bookedQtyPS.setString(4,EscapeString.getLengthString(b.getSecondVariant(), 1));
}else{
bookedQtyPS.setString(4,b.getSecondVariant());
if (b.getThirdVariant().equals("")){
bookedQtyPS.setString(5,EscapeString.getLengthString(b.getThirdVariant(), 1));
}else{
bookedQtyPS.setString(5,b.getThirdVariant());
if (b.getPackingType().equals("")){
bookedQtyPS.setString(6,EscapeString.getLengthString(b.getPackingType(), 1));
}else{
bookedQtyPS.setString(6,b.getPackingType());
if (b.getWarehouseCode().equals("")){
bookedQtyPS.setString(7,EscapeString.getLengthString(b.getWarehouseCode(), 1));
}else{
bookedQtyPS.setString(7,b.getWarehouseCode());
//cat.debug("b.getProjectItem(): "+b.getProjectItem());
if (b.getProjectItem().equals("")){
//cat.debug("entro in 1 b.getProjectItem().length: "+b.getProjectItem().length());
bookedQtyPS.setString(8,EscapeString.getLengthString(b.getProjectItem(), 1));
//bookedQtyPS.setString(8," ");
}else{
//cat.debug("entro in 2 b.getProjectItem().length: "+b.getProjectItem().length());
bookedQtyPS.setString(8,b.getProjectItem());
bookedQtyPS.setString(8," ");
//cat.debug("b.getSourceLot(): "+b.getSourceLot());
if (b.getSourceLot().equals("")){
bookedQtyPS.setString(9,EscapeString.getLengthString(b.getSourceLot(), 1));
}else{
bookedQtyPS.setString(9,b.getSourceLot());
bookedQtyPS.setString(9," ");
//cat.debug("b.getLotNumber(): "+b.getLotNumber());
if (b.getLotNumber().equals("")){
bookedQtyPS.setString(10,EscapeString.getLengthString(b.getLotNumber(), 1));
}else{
bookedQtyPS.setString(10,b.getLotNumber());
bookedQtyPS.setString(10," ");
//cat.debug("b.getItemConfiguration(): "+b.getItemConfiguration());
bookedQtyPS.setString(11,""+b.getItemConfiguration());
//cat.debug("b.getLocation(): "+b.getLocation());
if (b.getLocation().equals("")){
bookedQtyPS.setString(12,EscapeString.getLengthString(b.getLocation(), 1));
}else{
bookedQtyPS.setString(12,b.getLocation());
bookedQtyPS.setString(12," ");
ResultSet rs = bookedQtyPS.executeQuery();
and it returns 0 records.
I hope I explained it well.
Maybe you are looking for
-
How expensive is remote db table join? In performance tuning a sql statement, I have a query join a local table to two remote tables, it took 9 sec to return 6000+ rows. If I copy the two remote tables to local db, it took 700 msec. All joins/indexes
-
Add Image in the navigation bar of Help page
Hi, I wanted to add image next to to the Search in the Help page navigation bar as in snapshot below: I wanted to add an image i.e the the logo next to above button in navigation bar. I tried adding , howevr could only add as Header, not right in the
-
I tried downloading reset utilities but it keeps on saying it is for 32 bit(I have Windows 7). Please HELP
-
SSLEngine closing prematurely on SSLHandshakeException?
I have worked with the SSLEngine using non-blocked IO and it mostly works. I do have a problem when a client connects and I get WorkerThread-1, fatal error: 40: no cipher suites in common javax.net.ssl.SSLHandshakeException: no cipher suites in commo
-
Just got an Iphone - Receives email but can't send email to anyone ( POP ). Error Message : "The recepient ... was rejected by the server because it does not allow relaying." Please help............