SQL error with LIKE clause in statement
Can anyone explain how an SQL statement with a LIKE clause is executed properly?
Seems like it ought to be cut and dried, no pun intended!
When I run the following and set the requestor name = ?, and correctly type in the entire name, a result set (albeit abbreviated) will return.
But if I try to set the request param to LIKE I get an error of some kind, either invalid cursor state or NullPointer exception.
Here's my code.
Statement selstmt = connection.createStatement();
String preparedQuery = "SELECT DISTINCT AID, ACTIVE, REQUESTOR_NAME,REQUESTOR_EMAIL" +
" FROM CHANGE_CONTROL_USER, CHANGE_CONTROL_ADMIN " +
" WHERE REQUESTOR_NAME LIKE '%?%';";
String reqName = request.getParameter("requestor_name");
PreparedStatement prepstmt = connection.prepareStatement(preparedQuery);
prepstmt.setString(1, reqName);
ResultSet rslts = prepstmt.executeQuery();
rslts.next();
int aidn = rslts.getInt(1);
int actbox = rslts.getInt(2);
String reqname = rslts.getString(3);
String reqemails = rslts.getString(4);It's also returning only 1 record for some reason, as I have the following:
<% while (rslts.next()) { %>
<tr class="style17">
<td><%=reqname%></td>
<td><%=reqemails%></td>
<td><%=actbox %></td>
<td><%=aidn %></td>
</tr>
<%
rslts.close();
selstmt.close();
%>If I use
" FROM CHANGE_CONTROL_USER, CHANGE_CONTROL_ADMIN " +
" WHERE REQUESTOR_NAME = ?;";it will actually spit out the name and corresponding email properly, albeit just one record like I said.
Is there some kind of escape sequence I should be using that I'm not?
And why just the one record?
Any help or direction is appreciated!
Thanks.
I have working code for LIKE in PreparedStatement, and its equivalent in your case is something like this:Statement selstmt = connection.createStatement();
String preparedQuery = "SELECT DISTINCT AID, ACTIVE, REQUESTOR_NAME,REQUESTOR_EMAIL" +
" FROM CHANGE_CONTROL_USER, CHANGE_CONTROL_ADMIN " +
" WHERE REQUESTOR_NAME LIKE ?";
String reqName = request.getParameter("requestor_name");
PreparedStatement prepstmt = connection.prepareStatement(preparedQuery);
prepstmt.setString(1, "%" + reqName.trim() + "%");
ResultSet rslts = prepstmt.executeQuery();
rslts.next();
int aidn = rslts.getInt(1);
int actbox = rslts.getInt(2);
String reqname = rslts.getString(3);
String reqemails = rslts.getString(4);
Similar Messages
-
Hosting company does not support SQL query with OUTFILE clause
From my mysql database, I want to allow the user to run a query and produce a csv / text file of our membership database. Unfortunately, I just found out my hosting company does not support the SQL query with OUTFILE clause for MySQL database.
Are there any other options available to produce a file besides me running the query in phpadmin and making the file available to users.
Thanks. GeorgeMaybe this external Export Mysql data to CSV - PHP tutorial will be of help
Cheers,
Günter -
Error bind variable with "like %" clause ?
Hello everybody;
I would like to know how to do a like clause to bind variables, with this code i obtain 'ORA-00933: SQL command not properly ended' error
v_query:= 'UPDATE ' || collection(i) ||' SET REF_PLAN=:quatre_champ WHERE FAM_SIM like ''%'':prem_champ''%'' AND PRISE_V1P like ''%'':deux_champ''%'' AND BROCHE_V1P like ''%:trois_champ%''';
EXECUTE IMMEDIATE v_query USING quatre_champ,prem_champ,deux_champ,trois_champ;Maybe my " ' " are in a bad positions ?
Thanks for your help, regards.Hi,
try this
v_query :=
'UPDATE '
|| collection (i)
|| ' SET REF_PLAN =:quatre_champ WHERE FAM_SIM like'|| '''%:prem_champ%'''
|| ' AND PRISE_V1P like' || ''' %:deux_champ%'''
|| ' AND BROCHE_V1P like'||''' %:trois_champ%;'''
Of course not tested
Any efforts to give sample data and help us recreated the problem will be appreciated.
Cheers!!!
Bhushan -
SEQUENCE Select within an SQL Query with an ORDER BY statement
Does anyone know why you cannot use an ORDER BY statement within an SQL query when also selecting from a SEQUENCE? My query was selecting production data as a result of a filtered search. I want to take the results of the filtered search and create a transaction. I have a sequence for generating transaction numbers where I select NEXTVAL. Since I could possibly obtain multiple, yet distinct, rows based upon my search criteria, I wanted to use an ORDER BY statement to simplify and order the resulting row(s).
I was able to get the SQL select with SEQUENCE.NEXTVAL to work without the ORDER BY, so I know that my SQL is correct. Thanks in-advance.Okay,
I understand. You want the sequence assigned first and the you want to ORDER BY. You
can do this using pipelined functions. See here:
CREATE OR REPLACE TYPE emp_rec_seq AS OBJECT (
seq NUMBER,
ename VARCHAR2 (20),
job VARCHAR2 (20),
sal NUMBER
CREATE OR REPLACE TYPE emp_tab_seq AS TABLE OF emp_rec_seq;
CREATE OR REPLACE FUNCTION get_emp_with_sequence
RETURN emp_tab_seq PIPELINED
IS
my_record emp_rec_seq := emp_rec_seq (NULL, NULL, NULL, NULL);
BEGIN
FOR c IN (SELECT dummy.NEXTVAL seq, ename, job, sal
FROM emp)
LOOP
my_record.seq := c.seq;
my_record.ename := c.ename;
my_record.job := c.job;
my_record.sal := c.sal;
PIPE ROW (my_record);
END LOOP;
RETURN;
END get_emp_with_sequence;after that, you can do a select like this:
SELECT seq, ename, job, sal
FROM TABLE (get_emp_with_sequence)
order by enamewhich will get you this:
SEQ ENAME JOB SAL
1053 BLAKE MANAGER 2850
1054 CLARK MANAGER 2450
1057 FORD ANALYST 3000
1062 JAMES CLERK 950
1055 JONES MANAGER 2975
1052 KING MANAGER 20000
1060 MARTIN SALESMAN 1250
1063 MILLER CLERK 1300
1064 DKUBICEK MANAGER 12000
1056 SCOTT ANALYST 3000
1058 SMITH CLERK 800
1061 TURNER SALESMAN 1500
1059 WARD SALESMAN 1250Denes Kubicek
http://deneskubicek.blogspot.com/
http://htmldb.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
Tunning query with LIKE clause
Hi, is there any chance to improve execution plan for SQL query which is using LIKE clause?
Query:
SELECT * FROM [TABLE_NAME] WHERE ADDRESS LIKE :1 ESCAPE '\';
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 112K| 18M| 11361 (1)| 00:02:17 |
|* 1 | TABLE ACCESS FULL| [TABLE_NAME] | 112K| 18M| 11361 (1)| 00:02:17 |
Execution plan is far from ideal. Table has several millions of records.
This query is used by application to seach using patterns...
Any ideas?
Thx in advance!This example isn't entirely realistic. Your table T has only 1 column which is also indexed. Apparently, for small enough tables of one column it will search the entire index for the wildcard value. But if I add a second column, or base the single column version on a larger table, the optimizer uses a full table scan:
SQL> drop table t;
Table dropped.
SQL> CREATE TABLE t AS SELECT DBMS_RANDOM.STRING('a',100) a
2 ,DBMS_RANDOM.STRING('a',100) b
3 FROM user_objects;
Table created.
SQL>
SQL> CREATE INDEX t_idx ON t (a) COMPUTE STATISTICS;
Index created.
SQL>
SQL> SET autotrace traceonly explain
SQL>
SQL> SELECT *
2 FROM t
3 WHERE a LIKE '%acb%';
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=100)
1 0 TABLE ACCESS (FULL) OF 'T' (Cost=2 Card=1 Bytes=100)
SQL> drop table t;
Table dropped.
SQL> CREATE TABLE t AS SELECT DBMS_RANDOM.STRING('a',100) a
2 -- ,DBMS_RANDOM.STRING('a',100) b
3 FROM all_objects;
Table created.
SQL>
SQL> CREATE INDEX t_idx ON t (a) COMPUTE STATISTICS;
Index created.
SQL>
SQL> SET autotrace traceonly explain
SQL>
SQL> SELECT *
2 FROM t
3 WHERE a LIKE '%acb%';
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=20 Card=399 Bytes=39900)
1 0 TABLE ACCESS (FULL) OF 'T' (Cost=20 Card=399 Bytes=39900) -
ORA-06502: PL/SQL error with dimensions and roles
Hi everyone,
When executing a mapping that loads a cube we are always getting that ORA-06502: PL/SQL error character string buffer too small
The cube contains a number of dimensions, some of them with roles. We've checked that the error appears when we use two different lookup operators to fill dimension atributtes in the cube and its correspondent role. If we map dimension attributes with lookup operator, and the role attributes with constants, the mapping executes without any error. Moreover, even thought it doesnt make any sense, if we map the role dimension attributes with a lookup operator linked to a different dimension, it works too.
We think that this could be due to attributes names, maybe they are too long, but we have tried to make them shorter and still getting the same error.
Any ideas of what could be happening?
Thank you so much in advance.The return datatype in a PLSQL function is unconstrained. Which means it does not have a size.
The size is declared on the receiving end.
What size variable are you trying to return your value into?
Here is an example...
SQL>create or replace function my_func
2 return varchar2
3 is
4 begin
5 return USER;
6 end;
7 /
Function created.
SQL>declare
2 my_string varchar2(30);
3 begin
4 my_string := my_func;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL>declare
2 my_string varchar2(3);
3 begin
4 my_string := my_func;
5 end;
6 /
declare
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 4 -
Error with When Clause SQL Loader
I´'m trying to use WHEN clause in a control file, I'm following the documentation but it doesn't work still.
This is my control file:
LOAD DATA
CHARACTERSET UTF8
INTO TABLE DM08_CONDICIONADA
WHEN (STATUS_DESC='A')
APPEND
REENABLE DISABLED_CONSTRAINTS
FIELDS
TERMINATED BY '|'
"ID_COND" POSITION (1) INTEGER EXTERNAL ,
"DESC_COND" CHAR,
"STATUS_DESC" CHAR
I have the follow error:
SQL*Loader-350: Syntax error at line 26.
Expecting "(", found keyword append.
APPEND
^
I have tried with
WHEN STATUS_DESC='A'
but the error is the same. Do you have any ideas why is that?? I'm working with oracle 9i.
Greetings
Oscarwith:
LOAD DATA
CHARACTERSET UTF8
INTO TABLE DM08_CONDICIONADA
APPEND
WHEN STATUS_DESC='A' --->with (STATUS_DESC='A') neither
REENABLE DISABLED_CONSTRAINTS
FIELDSTERMINATED BY '|'
I have:
SQL*Loader-350: Syntax error at line 27.
Expecting "(", found keyword reenable.
REENABLE DISABLED_CONSTRAINTS
With:
LOAD DATA
CHARACTERSET UTF8
INTO TABLE DM08_CONDICIONADA
APPEND
REENABLE DISABLED_CONSTRAINTS
WHEN (STATUS_DESC ='A')
i have:
SQL*Loader-403: Referenced column STATUS_DESC not present in table DM08_CONDICIONADA.
I´m using the documentation...
-->full_fieldname or pos_spec-->operator--> char_string or Blanks --->
but it doesn't tell me where the when clause goes... i'm probing too with the forum information but i don't know what happens.
Thanks Jens -
Getting SQL errors with prepared statement in JDeveloper 10.1.3.2
I'm using oracle JDBC driver and I connect and update just fine from the SQL Worksheet in JDeveloper.
1) When I have more than 1 placeholder in my SQL statement, the last one is dropped so I get "Invalid column index".
2) When I add an extra one, it prepares OK but gets "ORA-01745: invalid host/bind variable name" on execution if the placeholder is inside the SQL closing paren (this situation is showed below).
3) When an extra one is outside the SQL closing paren, I get "ORA-00933: SQL command not properly ended"
I'm probably missing something obvious but here is the code I'm using:
public void insertToDB(Comment inrecord) throws Exception {
int idx = 0;
try {
this.initialize();
pstmt = conn.prepareStatement(
"INSERT INTO COMMENTS (COMMENT_ID, " +
"LOG_BUS_PROC_CDE, TYPE_CDE, SUBTYPE_CDE, " +
"REF_TYP_CDE, CREATE_USER, CREATE_DATE, " +
"UPDATED_USER, UPDATED_DATE, COMMENT_TEXT) VALUES(" +
"TO_TIMESTAMP('?','YYYY-MM-DD HH24:MI:SS.FF3'), ?, ?, " +
"?, ?, ?, TO_DATE(?,'MM/DD/YYYY'), NULL, NULL, ? ?)");
pstmt.setString(++idx,inrecord.getCommentID());
pstmt.setString(++idx,inrecord.getLogBusProcCDE());
pstmt.setString(++idx,inrecord.getTypeCDE());
pstmt.setString(++idx,inrecord.getSubTypeCDE());
pstmt.setString(++idx,inrecord.getRefTypCDE());
pstmt.setString(++idx,inrecord.getCreateUser());
pstmt.setString(++idx,inrecord.getCreateDate());
pstmt.setString(++idx,inrecord.getCommentTXT());
pstmt.executeUpdate();
conn.commit();
this.terminate();
catch (Exception e) {
conn.rollback();
this.terminate();
throw e;
}Hi,
actually you increment the index
pstmt.setString(++idx,inrecord.getCommentID());
which means you never have an index of 0 but always start with 1
Frank -
MAKING A SQL QUERY WITH LIKE SINTAX
Im trying to make a string with a sql query.
the object is return a select statement in the var string and the select statement must be return a string like that :
select item1, item2, item3 from table where
item1 like '%PEPE%' and item2 like '%COSA2%';
then I make a string like that :
lq_sql := 'select item1, item2, item3 from table where item1 like '||'%'||:P1_NOMBRE||'%'
but this give errors.
Any help? thanks in advanced and regards everybody.Hello,
If you check your statement in sql*plus this is how it will look like:
select 'select item1, item2, item3 from table where item1 like '||'%'||&P1_NOMBRE||'%' txt
from dual
Enter value for p1_nombre: 3
result:
TXT
select item1, item2, item3 from table where item1 like %3%
***You are missing single quotes before and after the % statement, as follows:
select 'select item1, item2, item3 from table where item1 like '||'''%'||&P1_NOMBRE||'%''' txt
from dual
Enter value for p1_nombre: 3
result:
TXT
select item1, item2, item3 from table where item1 like '%3%'BTW, i changed colon (:) to ampersand (&) to run it in SQL*plus but it should be a colon.
-Marilyn -
Error with ExecuteQuery() in prepared statement
Hello,
i' m a new one at java. I' m trying to build a web application in jsp and i have a problem in a simple at log in authentication.
My code is this:
<html>
<head>
<title>Welcome to the online Boat Shop, Inc.</title></head>
<body>
<%@ page language ="java" import = "java.io.*, java.lang.*, java.sql.*" %>
<% try
String strUsername = request.getParameter("USERNAME");
String strPassword = request.getParameter("PASSWORD");
Class.forName ("org.apache.derby.jdbc.ClientDriver");
Connection myConn = DriverManager.getConnection("jdbc:derby://localhost:1527/boatsdb","tony", "logo");
String strSQL = "SELECT USERNAME, PASSWORD FROM BOATDB where USERNAME = ? and PASSWORD = ?";
PreparedStatement stmt = myConn.prepareStatement(strSQL);
stmt.setString(1, "USERNAME");
stmt.setString(2, "PASSWORD");
ResultSet myResult = stmt.executeQuery(strSQL);
if(myResult.next()){
out.println("Login Succesful! A record with the given user name and password exists");
} else {
out.println("Login Failed. No records exists with the given user name and password");
myResult.close();
stmt.close();
myConn.close();
} catch(Exception e){
out.println(e);
%>
</body>
</html>
The problem is that prepared statement doesn't support executeQuery() method and i can find any solution. The error is this:
java.sql.SQLException: Method 'executeQuery(String)' not allowed on prepared statement. I already have some data in my database so that it can return results.
Thank you.
Edited by: antonis on May 3, 2008 6:13 AMthank you, that was the problem. It seems that i have also done mistakes in passing the username and password from the forms to the database for checking, because the message that i get always when i log is that there is no user with this username kai password.
<form method=GET action=log1.jsp>
<font size=5> Username <input type=text name="USERNAME" size=20>
</font>
<br>
<font size=5> Password <input type=text name="PASSWORD" size=20>
</font>
<br>
<input type=submit name=action value="Submit">
</form>
That's the forms and combined with the code in the fist post should have worked. Any ideas?
thanks again. -
Re Creating a chart getting an error with a 'Union All' statement
Hi
I have some data to chart with the following fields;
Product , Jul-08 , Aug-08, Sep-08 etc ...... to Jan-10.
The PRODUCT field is text showing the numerous Product Names
The Jul-08 & other month fields have numbers per product that is to be aggregated for that month & plotted on the line graph.
My SQL to create the first point on the chart is as below;
select null link, PRODUCT label, SUM(JUL-08) "FFF"
from "SCHEMANAME"."TABLENAME"
WHERE PRODUCT = 'FFF'
GROUP by PRODUCT
ORDER BY PRODUCT
This works fine until I want add the second point of this line graph using a 'union all' join as follows;
select null link, PRODUCT label, SUM(JUL_08) "FFF"
from "SCHEMANAME"."TABLENAME"
WHERE PRODUCT = 'FFF'
UNION ALL
select null link, PRODUCT label, SUM(AUG_08) "FFF"
from "SCHEMANAME"."TABLENAME"
WHERE PRODUCT = 'FFF'
I can't work out how I can join the other months on the line graph in one series.
The error is as follows;
1 error has occurred
Failed to parse SQL query:
select null link, PRODUCT label, SUM(OCT_09) "NCDS - STD" from "BI_A_DATA"."CDW_VS_NCDS_CALLS" WHERE PRODUCT = 'NCDS - STD' UNION ALL select null link, PRODUCT label, SUM(NOV_09) "NCDS - LOCAL" from "BI_A_DATA"."CDW_VS_NCDS_CALLS" WHERE PRODUCT = 'NCDS - LOCAL'
ORA-00937: not a single-group group function
Certain queries can only be executed when running your application, if your query appears syntactically correct, you can save your query without validation (see options below query source).
Can anyone assist?
I want a continuous Line Graph that shows all the months from Jul-08 , Aug-08, Sep-08 etc ...... to Jan-10 for the same product.
I will then add other series for the other products, ThanksOK, I thought each month would be separated by the different months in each selct subquery, but I see what you mean.
I'm creating a line graph for various PRODUCTS that has a numeric value for each month, from JUL_08 ..... for a number of months.
I want a LINE graph that shows the different totals each month for that PRODUCT.
The error advises that there are more values in the SELECT statement than the expected and to use Use the following syntax:
SELECT LINK, LABEL, VALUE
FROM ...
I then went on to use the '[ ]' brackets to separate data but this didn't fix the problem.
I've changed the script to suit as per your 'PERIOD' addition but now have the error as per below;
error script
1 error has occurred
Invalid chart query: SELECT null link, PRODUCT label, PERIOD, SUM(ABC) FROM (SELECT null link, PRODUCT, 'JUL_08' PERIOD,SUM(JUL_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT UNION ALL SELECT null link, PRODUCT, 'AUG_08' PERIOD,SUM(AUG_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT UNION ALL SELECT null link, PRODUCT, 'SEP_08' PERIOD,SUM(SEP_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT) GROUP BY link, PRODUCT, PERIOD
Use the following syntax:
SELECT LINK, LABEL, VALUE
FROM ...
Or use the following syntax for a query returning multiple series:
SELECT LINK, LABEL, VALUE1 [, VALUE2 [, VALUE3...]]
FROM ...
LINK URL
LABEL Text that displays along a chart axis.
VALUE1, VALUE2, VALUE3... Numeric columns that define the data values.
Note: The series names for Column and Line charts are derived from the column aliases used in the query.
My script amended;
SELECT null link, PRODUCT label, PERIOD, SUM(ABC)
FROM
(SELECT null link, PRODUCT, 'JUL_08' PERIOD,SUM(JUL_08)ABC
FROM BI_A_DATA.APEX_TEST
WHERE PRODUCT = 'ABC'
GROUP BY PRODUCT
UNION ALL
SELECT null link, PRODUCT, 'AUG_08' PERIOD,SUM(AUG_08)ABC
FROM BI_A_DATA.APEX_TEST
WHERE PRODUCT = 'ABC'
GROUP BY PRODUCT
UNION ALL
SELECT null link, PRODUCT, 'SEP_08' PERIOD,SUM(SEP_08)ABC
FROM BI_A_DATA.APEX_TEST
WHERE PRODUCT = 'ABC'
GROUP BY PRODUCT)
GROUP BY link, PRODUCT, PERIOD -
Hi
Please help!
I have a page which has an sql statement to show me the records from the last 100 days.
SELECT tblItems.intItemID, tblItems.txtProductCode, tblItems.txtModel, tblItems.memDescription, tblItems.dteDateIn, tblItems.txtSalesPrice, tblItems.txtLargeImage
FROM tblItems
WHERE (((tblItems.dteDateIn)>=DateAdd("d",-100,Date())))
This works when I test it in the dataset window but throws up the following error on my server running WinXP Pro & IIS.
Any guidance would be greatly appreciated.
Thanks
Lee
Server Error in '/instruments' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30516: Overload resolution failed because no accessible 'ToString' accepts this number of arguments.
Source Error:
Line 1: <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="utf-8" %>
Line 2: <%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
Line 3: <MM:DataSet
Line 4: id="DataSet1"
Line 5: runat="Server"
Source File: E:\Websites\instruments\latest.aspx Line: 3
Show Detailed Compiler Output:
Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618Hi
Thanks for the reply.
Yes .Net 1.1 is installed.
In fact, my application wouldnt work until I installed .Net version 2
Regards -
"catch is unreachable" compiler error with java try/catch statement
I'm receiving a compiler error, "catch is unreachable", with the following code. I'm calling a method, SendMail(), which can throw two possible exceptions. I thought that the catch statements executed in order, and the first one that is caught will execute? Is their a change with J2SE 1.5 compiler? I don't want to use a generic Exception, because I want to handle the specific exceptions. Any suggestions how to fix? Thanks
try {
SendMail(....);
} catch (MessagingException e1) {
logger.fine(e1.toString());
} catch (AddressException e2) {
logger.fine(e2.toString());
public String SendMail(....) throws AddressException,
MessagingException {....I found the problem:
"A catch block handles exceptions that match its exception type (parameter) and exception types that are subclasses of its exception type (parameter). Only the first catch block that handles a particular exception type will execute, so the most specific exception type should come first. You may get a catch is unreachable syntax error if your catch blocks do not follow this order."
If I switch the order of the catch exceptions the compiler error goes away.
thanks -
Boolean error with a If else statement
Hello, i am new to java, and the only other programing language i have used is pascal, and compared to java its ALOT different any ways my problem. I am trying to write a simply little program which random selects a number between 1 and 10, i did that fine got to show that on screen with no probelm . Next i wanted to but in a if else statement, depending which numbers was selected it would show a different message this is where i am getting a probelm, here is the code for the whole thing:
// randomColour
import javax.swing.JOptionPane;
public class randomColour {
public static void main ( String args [])
int value;
value = 1 + ( int ) ( Math.random() * 10 );
if (value = "1" )
System.out.println("Green");
else
System.out.println("Blue");
System.exit( 0 );
} // end mainWhen i try to Compile it comes up with error saying required:boolean why is this? and what can i do to change to fix it?A single = is used to indicate assignment. You are testing for equality which requires ==. Also, "1" is a String. Value is an int. Changeif value = "1" to if value == 1Mark
-
Using "?" in SQL sataements with LIKE in EJBs
The sql statement of a finder methode of an entity Bean
should look like this:
SELECT id FROM books WHERE titles LIKE 'abc%'
where abc is the overgiven methode parameter.
To do this I tried to enter the following statement in deploment tool:
SELECT id FROM books WHERE titles LIKE '\?%' {escape '\'}
But because ? is inside of ' ' the server can not interprate it as a parameter sign!!! and the server throws an Exception : too few or too much parameters
I have also tried deverse other combination but without any successSorry the query posted by me will not work.
Build the query like
String query = "select id from books where title like ?";
There is no need for single quotes for strings if you are using prepared statement. singe quotes are used only when u not using PreparedStatement.
Do not put any single quotes around the ?.
and append the % to the variable name when you set the parameter on the prepared statement.Then it should work withour problems.
sorry for the inconvenience.
regards,
Abhishek.
Maybe you are looking for
-
Java.io.NotSerializableException error when starting 8.1 app server
I am running JES 054Q with uwc deployed on the app server 8.1 (along with am, portal, and da). I am getting a java.io.NotSerializableException for com.sun.uwc.common.util.UWCPreferences when the application server starts. Any access to get attributes
-
Hi all, Can any one tell me the standard reports taken from each of the BW statistics cubes and multiproviders. Thanks in Advance Ramesh
-
Is there any way to import/export email from a user's account?
-
DUMP ERROR: INVALID PARAM VERB : ENABLEAPSSO
I am working on CRM 4.0. After executing the transaction CRMD_ORDER_BP, I got short dump "Exception condition INVALID PARAM VERB: ENABLESAPSSO raised." with "RAISE_EXCEPTION" C "SAPLOLEA " or "LOLEAU10 " "AC_FLUSH_CALL_INTERNAL" . How to solve thi
-
BP creation in waiting - how to solve ?
Hello, I'm using 'BAPI_BUPA_CREATE_FROM_DATA' into a report scheduled by job. Sometime the job is waiting for a lot time. I searched and the cause is that an user would modify a business partner, he got an error and he close the windows in a wrong