What Is the Correct Syntax?
I am searching a database, order the search result by some criterion supplied by users and ASC/DESC is also supplied by user's selection. How do I write the query statement?
public Collection getBeans( String memberName, String sortCriterion, String order )
throws IllegalArgumentException, DatabaseException, BadInputException
String query = "SELECT thread_id, message_receiver, message_sender, article_title FROM message_thread WHERE message_receiver = '" + memberName + "' ORDER BY + '" sortCriterion + '" + " " + '"order + "'";
My question is about the syntax of building up the query string.
Here is the entire code:
public Collection getThreadBeans_forReceiver_withSortSupport_limit_mysql( String memberName, int offset, int rowsToReturn, String sort, String order )
throws IllegalArgumentException, DatabaseException, BadInputException
if ( offset < 0 ) throw new IllegalArgumentException( "The offset < 0 is not allowed." );
if ( rowsToReturn <= 0 ) throw new IllegalArgumentException( "The rowsToReturn <= 0 is not allowed." );
if ( ( !sort.equals( "thread_last_post_date" ) ) &&
( !sort.equals( "thread_creation_date" ) ) &&
( !sort.equals( "message_sender" ) ) &&
( !sort.equals( "thread_reply_count" ) ) &&
( !sort.equals( "thread_view_count" ) ) )
throw new BadInputException( "Cannot sort, reason: dont understand the criteria '" + sort + "'." );
if ( ( !order.equals( "ASC" ) ) &&
( !order.equals( "DESC" ) ) )
throw new BadInputException( "Cannot sort, reason: dont understand the order '" + order + "'." );
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
Collection retValue = new ArrayList();
String query = "SELECT thread_id, message_receiver, message_sender, article_title, last_post_member_name, thread_topic, thread_body, thread_creation_date, thread_last_post_date, thread_type, thread_option, thread_status, thread_view_count, thread_reply_count, thread_duration FROM message_thread WHERE message_receiver = '" + memberName + "' ORDER BY " + sort + " " + order;
try
conn = DBConnection.getDBConnection();
stmt = conn.prepareStatement( query );
stmt.setString( 1, memberName );
stmt.setInt( 2, offset );
stmt.setInt( 3, rowsToReturn );
rs = stmt.executeQuery();
while ( rs.next() )
ThreadBean bean = new ThreadBean();
bean.setThreadID( rs.getInt( "thread_id" ) );
bean.setReceiver( rs.getString( "message_receiver" ) );
bean.setSender( rs.getString( "message_sender" );
bean.setTitle( rs.getString( "article_title" );
bean.setLastPostMemberName( rs.getString( "last_post_member_name" ) );
bean.setPostTopic( rs.getString( "thread_topic" ) );
bean.setPostBody( rs.getString( "thread_body" ) );
bean.setThreadCreationDate( rs.getTimestamp( "thread_creation_date" ) );
bean.setThreadLastPostDate( rs.getTimestamp( "thread_last_post_date" ) );
bean.setThreadType( rs.getInt( "thread_type" ) );
bean.setThreadOption( rs.getInt( "thread_option" ) );
bean.setThreadStatus( rs.getInt( "thread_status" ) );
bean.setThreadViewCount( rs.getInt( "thread_view_count" ) );
bean.setThreadReplyCount( rs.getInt( "thread_reply_count" ) );
bean.setThreadDuration( rs.getInt( "thread_duration" ) );
retValue.add( bean );
return retValue;
catch( SQLException sqle )
sqle.printStackTrace();
throw new DatabaseException( "Error executing SQL in ListThreadHandler.getBeans_inForum_withSortSupport_limit_mysql." );
finally
if ( conn != null )
try
stmt.close();
stmt = null;
conn.close();
catch( SQLException sqlEx )
System.out.println( "Problem occurs while closing " + sqlEx );
conn = null;
}
Similar Messages
-
What is the correct syntax for using a variable in an ad hoc query?
Hi all
I am an occasional DB user and at the moment need to update about 1000+ records so that a certain column gets a unique value.
So I thought that I would use a variable for this.
I then built this kind of SQL statement for just a small subset of the records:
variable recNumber number;
exec :recNumber := 1;
UPDATE TABLE_TO_BE_UPD
SET COL_TO_BE_UPD = COL_TO_BE_UPD + recNumber
WHERE COL_TO_BE_UPD IN ('VAL_A','VAL_B');
I get the invalid SQL statement error when attempting to execute above (besides the prompt that asks for a value which I would like to omit).
Anyway I also tried this one:
CREATE SEQUENCE seqCounter;
UPDATE TABLE_TO_BE_UPD
SET COL_TO_BE_UPD = COL_TO_BE_UPD + seqCounter.NEXTVAL
WHERE COL_TO_BE_UPD IN ('VAL_A','VAL_B');
From this one I got the error ORA-01722: invalid number...I am guessing this comes because seqCounter is of type number and the COL_TO_BE_UPD is of type character...(?)
So what I would like to ask is what is the correct way to define and use a counter type of variable to append a number at the end of a character string?
Also another question that I would like to ask is that are variables that are used in ad hoc queries also called 'bind variables'?
Thanks muchlyIf you want to append a unique number to a column then this would do it:
UPDATE TABLE_TO_BE_UPD
SET COL_TO_BE_UPD = COL_TO_BE_UPD ||to_char(rownum)
WHERE COL_TO_BE_UPD IN ('VAL_A','VAL_B'); -
What is the correct Syntax to export to SWF using VBScript
I am trying to export to swf using Indesign Server but i'm struggling to find the correct syntax using VBScript
can someone point me in the correct direction or maybe give me this info?
Thanks in advance
TomMalcolm,
Just string the keywords in a row, and let 'er rip.
The Store used to have a more sophisticated search capability known as Power Search, which allowed fielded entry. But it seems to have disappeared a few releases ago. -
What's the correct syntax for this?
Hey guys
If...
trace(rowsHolder.getChildByName("mc"+newStr).y);
...correctly outputs the y coordinate of (in this case) mc001, how do I output the y coordinate of a movieClip called item_base_mc that's within the timeline of mc001?
trace(rowsHolder.getChildByName("mc"+newStr).item_base_mc.y);
...gives me a display object error.
I've tried permutations of the above with [] brackets in various places, but haven't cracked the code.
What would be the correct way to write it?
Thanks for taking a look.
ShaunI don't know how to really explain this, but from documentation you will notice - getChildByName() - is actually a function from - DisplayObject - not MovieClip.
Link here provides a better explanation!
http://curtismorley.com/2007/06/13/flash-cs3-flex-2-as3-error-1119
GOOD LUCK -
What is the correct syntax to have the report log into different databases?
Hi,
My current Oracle Reports are called against several databases, depending on region. I pass 'userid=reports/new1@tsoc' as one of teh parameters to access the 'tsoc' db. I just as well call 'userid=reports/new1@penang'.
This syntax does not appear to work when placed in the BI Publisher URL as follows:
http://seerus04.soco.agilent.com:9704/xmlpserver/emerald/tutorial/tutorial.xdo?_xpf=&_xpt=0&_xdo=%2Femerald%2Ftutorial%2Ftutorial.xdo&_xt=tutorial&_xf=html&_xmode=0&userid=reports/[email protected]
Thn in advance,
GaryJorge,
I have 11 databases in different regions. Oracle Reports allows me to pass in the database I wish to connect to.
This is extremely pertinent to my evaluation as I cannot justify having 11 seperate instances for each of my reports.
If what you say is true, I would consider BIP a poor subsitute for Oracle Reports.
Thx,
Gary -
What's the correct syntax for animate scale
I have tried to animate the scale transformation of an object from code.
I had a little success with the code from here:
http://stackoverflow.com/questions/5029035/how-do-we-add-css-animation-in-jquery
But animating the scale looks jerky on the iPad with this hack.
There must be an option of doing it from within Edge since a timeline animation which does the same (just transform scale of an object over time) runs smooth.
I know there are jQuery extensions for things like that but I don't want to interfere with anything Edge does itself.
Can someone give me a hint what syntax I need for animating the scale of an object within Edge?Hi Bittamer,
There is no built-in code to animate objects. If you don't want to use the CSS scale code, you can use jQuery animate to animate the width and height props of your object, like so:
sym.yourHeight = 500;
sym.yourWidth = 500;
sym.$("your_symbol").animate({height:sym.yourHeight, width:sym.yourWidth}, 500, 'swing'); -
What is the correct syntax for Sumif when condition is for a text string?
B2 and b3 both contain the text "Grc".
C2 contains 1 and C3 contains 2.
F2 contains a Sumif that reads as: =SUMIF(B2:B10, "=Grc", C2:C10)
The result is "0" when it should yield 3
I can't figure out what happened.Hi ishii,
Your screen shots make no sense to me. I am using Numbers'09 on a MacBook Pro running OS X. Please tell us what device, operating system and app you are using. You still have not told us.
This forum is for Numbers on a Mac running OS X. Is your screen shot from an iOS device?
I don't know anything about Numbers for iOS.
Or are you using Excel?
I can not help you. If you are using an iPad, you will get a better answer in this forum:
https://discussions.apple.com/community/app_store/iwork_for_ios?view=discussions
Regards,
Ian. -
What is the correct syntax to run a procedure in SQL Workshop
I have a procedure I want to test in SQL Workshop in APEX. It has one argument but I don't know the syntax to include the argument. I have put
begin download_attached_files;
end;
how do I manually assign a number to this procedure?
( i.e this doesn't work:
begin download_attached_files=43; end;)Hi,
Try:
BEGIN
EXECUTE download_attached_files(43);
END;Andy -
Can't figure out the correct syntax for this select statement
Hello,
The following statement works great and gives the desired results:
prompt
prompt Using WITH t
prompt
with t as
select a.proj_id,
a.proj_start,
a.proj_end,
case when (
select min(a.proj_start)
from v b
where (a.proj_start = b.proj_end)
and (a.proj_id != b.proj_id)
is not null then 0 else 1
end as flag
from v a
order by a.proj_start
select proj_id,
proj_start,
proj_end,
flag,
-- the following select statement is what I am having a hard time
-- "duplicating" without using the WITH clause
select sum(t2.flag)
from t t2
where t2.proj_end <= t.proj_end
) s
from t;As an academic exercise I wanted to rewrite the above statement without using the WITH clause, I tried this (among dozens of other tries - I've hit a mental block and can't figure it out):
prompt
prompt without with
prompt
select c.proj_id,
c.proj_start,
c.proj_end,
c.flag,
-- This is what I've tried as the equivalent statement but, it is
-- syntactically incorrect. What's the correct syntax for what this
-- statement is intended ?
select sum(t2.flag)
from c t2
where t2.proj_end <= c.proj_end
) as proj_grp
from (
select a.proj_id,
a.proj_start,
a.proj_end,
case when (
select min(a.proj_start)
from v b
where (a.proj_start = b.proj_end)
and (a.proj_id != b.proj_id)
is not null then 0 else 1
end as flag
from v a
order by a.proj_start
) c;Thank you for helping, much appreciated.
John.
PS: The DDL for the table v used by the above statements is:
drop table v;
create table v (
proj_id number,
proj_start date,
proj_end date
insert into v values
( 1, to_date('01-JAN-2005', 'dd-mon-yyyy'),
to_date('02-JAN-2005', 'dd-mon-yyyy'));
insert into v values
( 2, to_date('02-JAN-2005', 'dd-mon-yyyy'),
to_date('03-JAN-2005', 'dd-mon-yyyy'));
insert into v values
( 3, to_date('03-JAN-2005', 'dd-mon-yyyy'),
to_date('04-JAN-2005', 'dd-mon-yyyy'));
insert into v values
( 4, to_date('04-JAN-2005', 'dd-mon-yyyy'),
to_date('05-JAN-2005', 'dd-mon-yyyy'));
insert into v values
( 5, to_date('06-JAN-2005', 'dd-mon-yyyy'),
to_date('07-JAN-2005', 'dd-mon-yyyy'));
insert into v values
( 6, to_date('16-JAN-2005', 'dd-mon-yyyy'),
to_date('17-JAN-2005', 'dd-mon-yyyy'));
insert into v values
( 7, to_date('17-JAN-2005', 'dd-mon-yyyy'),
to_date('18-JAN-2005', 'dd-mon-yyyy'));
insert into v values
( 8, to_date('18-JAN-2005', 'dd-mon-yyyy'),
to_date('19-JAN-2005', 'dd-mon-yyyy'));
insert into v values
( 9, to_date('19-JAN-2005', 'dd-mon-yyyy'),
to_date('20-JAN-2005', 'dd-mon-yyyy'));
insert into v values
(10, to_date('21-JAN-2005', 'dd-mon-yyyy'),
to_date('22-JAN-2005', 'dd-mon-yyyy'));
insert into v values
(11, to_date('26-JAN-2005', 'dd-mon-yyyy'),
to_date('27-JAN-2005', 'dd-mon-yyyy'));
insert into v values
(12, to_date('27-JAN-2005', 'dd-mon-yyyy'),
to_date('28-JAN-2005', 'dd-mon-yyyy'));
insert into v values
(13, to_date('28-JAN-2005', 'dd-mon-yyyy'),
to_date('29-JAN-2005', 'dd-mon-yyyy'));
insert into v values
(14, to_date('29-JAN-2005', 'dd-mon-yyyy'),
to_date('30-JAN-2005', 'dd-mon-yyyy'));Hi, John,
Not that you asked, but as you proabably know, analytic functions are much better at doing this kind of thing.
You may be amazed (as I continually am) by how simple and efficient these queries can be.
For example:
WITH got_grp AS
SELECT proj_id, proj_start, proj_end
, proj_end - SUM (proj_end - proj_start) OVER (ORDER BY proj_start) AS grp
FROM v
SELECT ROW_NUMBER () OVER (ORDER BY grp) AS proj_grp
, MIN (proj_start) AS proj_start
, MAX (proj_end) AS proj_end
FROM got_grp
GROUP BY grp
ORDER BY proj_start
;Produces the results you want:
PROJ_GRP PROJ_START PROJ_END
1 01-Jan-2005 05-Jan-2005
2 06-Jan-2005 07-Jan-2005
3 16-Jan-2005 20-Jan-2005
4 21-Jan-2005 22-Jan-2005
5 26-Jan-2005 30-Jan-2005This is problem is an example of Neighbor-Defined Groups . You want to GROUP BY something that has 5 distinct values, to get the 5 rows above, but there's nothing in the table itself that tells you to which group each row belongs. The groups are not defined by any column in hte table, but by relationships between rows. In this case, a row is in the same group as its neighbor (the row immediatly before or after it when sorted by proj_start or proj_end) if proj_end of the earlier row is the same as proj_start of the later row. That is, there is nothing about 03-Jan-2005 that says the row with proj_id=2 is in the first group, or even that it is in the same group with its neighbor, the row with proj_id=3. Only the relation between those rows, the fact that the earlier row has end_date=03-Jan-2005 and the later row has start_date=03-Jan-2003, that says these neighbors belong to the same group.
You're figuring out when a new group starts, and then counting how many groups have already started to see to which group each row belongs. That's a prefectly natural procedural way of approaching the problem. But SQL is not a procedural language, and sometimes another approach is much more efficient. In this case, as in many others, a Constant Difference defines the groups. The difference between proj_end (or proj_start, it doesn't matter in this case) and the total duratiojn of the rows up to that date determines a group. The actual value of that difference means nothing to you or anybody else, so I used ROW_NUMBER in the query above to map those distinct values into consecutive integers 1, 2, 3, ... which are a much simpler way to identify the groups.
Note that the query above only requires one pass through the table, and only requires one sub-query. It does not need a WITH clause; you could easily make got_grp an in-line view.
If you used analytic functions (LEAD or LAG) to compute flag, and then to compute proj_grp (COUNT or SUM), you would need two sub-queries, one for each analytic function, but you would still only need one pass through the table. Also, those sub-queries could be in-line views; yiou would not need to use a WITH clause. -
What is the correct dev environment?
I'm using Sun Java 1.6 on an Ubuntu 8.04 platform using an eclipse 3.2 IDE. It's the pits! I tried to convince my boss in the beginning to use a Fedora OS with fedora Eclipse and Iced-tea java. I read somewhere that iced-tea is basically the same as Sun Java, except that the sound components aren't yet OSS (Sun is changing this). My question to you all is: Can I dev jee apps with fedora eclipse and iced-tea (latest) and have these apps be truly cross-platform? Will the java I write on the fedora platform be truly as cross-platform as Sun's Java, sound not withstanding?
Jusclark-Oracle wrote:
What is the correct syntax for referencing a page item (P23_ID, for example) in a PL/SQL page process, after submit?
See "About Referencing Session State" in the documentation.
Within an anonymous block in an APEX page process, use the standard bind variable syntax:
:P23_ID
In general, use bind variable syntax when referencing session state values in SQL or DML:
select
ename
into
:p23_name
from
emp
where
empno = to_number(:p23_id);
and obviously when assigning values to the item:
:P23_ID := foo.nextval;
PL/SQL function references v('p23_id') and nv('p23_id') [for number values] must be used to access values in stored program units called from APEX, although it's usually better to pass the values as parameters: foo(:p23_id). -
What is the setVariable syntax for AS3
Hi,
I am having issues with setting a variable in AS3 SWF playing inside a Dir12
spriteObjRef.setVariable(variableName, newValue)
In the context of ActionScript 3, this method is only supported on a Flash object, not on a
spriteObjectRef.
What would the Flash Object syntax be??
Thanks,
JimJusclark-Oracle wrote:
What is the correct syntax for referencing a page item (P23_ID, for example) in a PL/SQL page process, after submit?
See "About Referencing Session State" in the documentation.
Within an anonymous block in an APEX page process, use the standard bind variable syntax:
:P23_ID
In general, use bind variable syntax when referencing session state values in SQL or DML:
select
ename
into
:p23_name
from
emp
where
empno = to_number(:p23_id);
and obviously when assigning values to the item:
:P23_ID := foo.nextval;
PL/SQL function references v('p23_id') and nv('p23_id') [for number values] must be used to access values in stored program units called from APEX, although it's usually better to pass the values as parameters: foo(:p23_id). -
What is the correct way to format file paths and names in the structapp file?
I am trying to create a structured application to export fm files as xml, and probably read the xml back to fm.
In the structured application file (structapp), I need to specify the locations of the various files (DTD, read/write, template, etc). I would like to place these files on a shared server so others can use the same structapp file (that is, a cop of it). What is the correct way to format the file paths and names? Can folders folder names and file names have spaces in them? I tried the following, for example:
\\serverName\shareName\folder 1\folder 2\file name.dtd
I use the same format for the template file and the read/write rules file.
When I try to save an fm file to xml, FrameMaker says that it cannot read the DTD; however, the resulting xml file appears to be well-formed. The DOCTYPE element in the resulting xml is formatted with forward slashes and spaces replaced with %20.
I tried using forward slashes and replacing spaces with %20, but then I get an error about reading the read/write rules.
NOTE: I have another structured application to read xml into fm. This application does not have a DTD file. The template and read/write rules files are specified as above. Except for complaining about a lack of a DTD, the application works fine; it even applies an XSLT in the process. Again, when I DO add a DTD to this latter application, I get the same complaint about not being able to read the DTD.
I am using fully patched FrameMaker 9 in Windows XP.
Thanks,
VanHi Van,
The XML parser and FrameMaker are not the same thing. The Error Log says which component created which message. The XSL processor is another option that can throw messages. The "\\server\path\some.dtd" syntax in structapps.fm seems to be fine for some tools, as Internet Explorer with XML tools successfully finds the DTD which appears as "//server/path/some.dtd" in the XML. But apparently Xerxes, the XML parser bundled with FrameMaker, does not like this notation.
If you have a path with a drive letter, "H:\path\some.dtd", FrameMaker turns that into "file:///H:/path/some.dtd". It seems, Xerces would like to see "file:/" in front of absolute paths.
This is what I have in structapps.fm:
Template: \\server\path\projecttemplate.fm
DTD: some.dtd
Read/write rules: \\server\path\projectrules.txt
DOCTYPE: …
Entity locations
Entity search paths
1: \\server\path\
In the structapps.fm I have the DTD without path information. The resulting XML (without XSL postprocessing) then contains just the file name with a relative path back to the book folder (when saving a book as XML). It therefore requires the DTD to be available at this place. I handle this using an event script that fires for NotePreSaveXml and copies the DTD to the folder of the original document.
As I always use XSL postprocessing and using XSLT1 it is not possible to have the doctype-system as a parameter I have this in my XSL stylesheet:
<xsl:output doctype-system="some.dtd" />
For the resulting XML the DTD is expected to be in the same folder as the XML file. This is handled by the same event script as above, it therefore copies the DTD to the source and the target folder.
Bottom line: If you want/have to use UNC paths, you have to do some programming to work around a FrameMaker bug.
- Michael -
What is the correct cable for iMac 11,2 Intel core i3, mini DVI to VGA or mini display port to VGA to hook up to projector? Thanks!
mini-DisplayPort.
Regards. -
What is the correct URL for my ical on my MacBook so that all devices will have the same information? And how/where do I update that?
Thank you.I had major issues with the iPhone 4s battery, however it’s resolved.
The tech who set the phone up at the Apple store did so with little training.
if you have a mobile me account. First go and move all your data to the cloud by going on your computer and logging in at me.com/move. The cloud has replaced mobile me, so there is no need for those two accounts
Also make sure that for any of your email accounts you set them up to fetch, not push. My tech person set them all to have the email servers push data to the phone. The new iphone4s antenna is extremely strong so it will continually try to access stuff that is pushed–***** a lot of battery life doing this. It makes it worse if you have exchange 2010 accounts. Something about changes made to exchange really suck battery life from devices that access such accounts.
turning of locator and the push notifications from facebook--they have a lot! -
Macromedia Dreamweaver activation phone number is no longer active. What is the correct number?
Try http://helpx.adobe.com/x-productkb/policy-pricing/activation-help-legacy-macromedia-produc ts.html
Maybe you are looking for
-
Problems with iTunes and iPod running under Windows Vista
I recently changed my computer. I now have an HP Pavilion running windows Vista (use to have XP). I have a video iPod -30GB. I downloaded iTunes onto the new equipment without incident, but that is the last thing that went smoothly. I can no longer w
-
Hi Experts, I am trying to install sap IDES ECC 6 EhP 7 from scratch. Everything was doing well but I got an error on starting instance. SAPMMC Console Process disp+work.EXE do not change from status: "Server in State STARTING" (Yellow). I have been
-
Cannot install CS6 on Macbook Pro OSX 10.8
So I took advantage of a sale for educators and bought Photoshop CS6 and I'm following the instructions, I downloaded the Akamai download manager and followed the instructions on the .pdf that it came with. After the download concluded, I click on op
-
CAN YOU USE A FLASH TEMPLATE IN IWEB?
I have recently created my website using iWeb....albeit with much help from this forum...and am very pleased with the results. I would like to, however, have my site open with a Flash introduction. I have seen many affordable Flash Templates for sale
-
viewing on my hp 2310m monitor is very condensed and small, toolbars are ok to view