How to get prepared string before sending to sql
Hi
I want the prepared string before sending to Sql (After substitution and setXXX), is it possible to do this? if yes, how ?
PreparedStatement ps = cn.prepareStatement("select * from table1 where name= ''?'' ");
ps.setString(1, "mytable")
<-- I want the prepared string before sending to Sql (After substitution and setXXX) -->
ResultSet rs = ps.executeQuery();
Thanks
Ali
As I mentioned, I want Sql Text before execution
n (getting resultSet), and after whole of setXXXs,No way, I believe.
I have tried in many ways, let me put down my work.
String query = "'Select * from dept where deptno=?'";
System.out.println("Before : "+query);
PreparedStatement ps = con.prepareStatement("select "+query+",? from Dual");
ps.setInt(1,50);
ResultSet rs = ps.executeQuery();
if(rs.next()) {
System.out.println("After : "+rs.getString(1));
ps.close();
con.close();I have tried in these lines, to capture the sql query, but it is failing at execution and the exception is 'bind variable not found'. So, I think you need to implement your own class to construct this query. Getting the details from DatabaseMetadata to see how the driver's setter methods works and you can use the same logic in your custom class.
Good luck.
Similar Messages
-
How to get server certificate before sending off confidential content?
If my mail client knows for example the SHA1 value of TLS/SSL enabled receiving MTA's certificate, subversion of DNS and Root-CAs could be prevented if after establishing the connection, the com.sun.mail.smtp.SMTPTransport.serverSocket were accessible to retrieve that certificate:
X509Certificate[] certs = null;
if (serverSocket instanceof SSLSocket) {
SSLSocket ssl = (SSLSocket) serverSocket;
certs = ssl.getSession().getPeerCertificateChain();
byte[] sha1 = MessageDigest.getInstance("SHA1").digest(
certs[0].getEncoded());
//TODO now validate with the sha1 you already know
Unfortunately com.sun.mail.smtp.SMTPTransport (let alone javax.mail.Transport) have a public getServerSocket() or even better a getX509ServerCertificates() method.
Any other ideas how to get at those certificates short of using gnu classpathx?
See also http://forum.java.sun.com/thread.jspa?threadID=615422I found the solution for server side. We will use Handler. And base on technology to generate web service's stuff (my server using axis, but my client using jaxWS), we have different ways to implement and deploy Handler. My purpose is only write input/output xml message to log, so with my server, I only adjust server-config.wsdd as bellow:
<deployment
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler name="log" type="java:org.apache.axis.handlers.LogHandler"/>
<globalConfiguration>
<requestFlow>
<handler type="log"/>
</requestFlow>
<responseFlow>
<handler type="log"/>
</responseFlow>
</globalConfiguration>
<transport
name="http" pivot="java:org.apache.axis.transport.http.HTTPSender"/>
</deployment>
But now I still can not control directory and log file name yet (now it's axis.log by default).
Edited by: mydesktop on Nov 15, 2010 6:20 PM -
How to get a string "yyyyMMdd" into date like MM/dd/yyyy?.
Hi
How to get a string "yyyyMMdd" into date like MM/dd/yyyy?. i have used
SimpleDateFormat.parse but it is giving long value. i want to disply the date
like MM/dd/yyyy
thank youDo you want the string rearranged or do you want to create an instance of some form of Date class?
If you want to rearrange the string you could just do it yourself provided you know the date string is going to be of the format yyyyMMdd.
something like this:
String newDate = origStr.charAt(4) + origStr.charAt(5) + "/" + origStr.charAt(6) + origStr.charAt(7) + "/" ...etc. -
Magic Packet - How to get my router to send one
I have the Quantum Gateway 1100 router. I have a NAS Server on my home network. The NAS server has the capability to Wake on LAN if the router can send that packet. Can anyone tell me how to get the router to send the Wake-on-Lan packet to the server. FIOS Tech Support is completely and totally useless.
Hi,
You can do a fresh installation using the installer bits available at the following link/location Download CS5.5 products
For suites, you need to download and copy both .7z and .exe in the same folder. Clicking .exe will extract all relevant installer files. You can then install the suite. Use your existing Serial number when prompted.
regards
Aj -
How to get alternative strings in list of strings.
Hi experts,
how to get alternative strings in list of strings.
eg
'country1, italy, country2, india, country3, paris, country4, scottland, country5, rome'
from the above list i need to fetch all the countries and their names separately.
like country1, country2, country3, country4, country5
italy, india, paris, scottland, rome
i am trying the above one in the below fashion
SELECT SUBSTR
('country1, italy, country2, india, country3, paris, country4, scottland, country5, rome',
1,
INSTR
('country1, italy, country2, india, country3, paris, country4, scottland, country5, rome',
1,
1
- 1
FROM DUAL
can you please any one help meIf you want the data to be more stuctured, and useful:
col col_name for a20
col col_value for a20
var inlist VARCHAR2(2000)
exec :inlist := 'country1, italy, country2, india, country3, paris, country4, scottland, country5, rome';
exec :inlist := replace(:inlist,' ')
select max(decode(mod(lvl,2),1,value)) col_name
,max(decode(mod(lvl,2),0,value)) col_value
from (select substr(:InList,start_pos+1, end_pos-start_pos-1) value
,lvl
from (select :InList
,case when level = 1 then
0
else
instr(:InList,',',1,level-1)
end start_pos
,case when instr(:InList,',',1,level) = 0
then length(:InList)+1
else
instr(:InList,',',1,level)
end end_pos
,level lvl
from dual
connect by level <=length(:InList)-length(replace(:InList,','))+1
group by ceil(lvl/2)
order by 1;
COL_NAME COL_VALUE
country1 italy
country2 india
country3 paris
country4 scottland
country5 rome
Untested on 10g
Then you could stragg the rows together ... -
How to get the process id of a sql statement or a session ....
How to get the process id of a sql statement or a session . ..?
ThanksWhat about this?
SELECT pid
FROM v$session s, v$process p
WHERE p.addr = s.paddr
AND s.sid = :sid; -- replace :sid with your session idRegards.
Al -
How to split the string by datetime in sql
Hi,
How to split the string by datetime in sql, I've a table with comments column stores comments by datetime, while selecting I want to split and show as in rows by each jobref.
can anyone help me in this please.
Thanks,declare @callcentre table (comments varchar(max),lbiref varchar(200))
insert into @callcentre
select '(28/10/2014 14:56:14) xyz ..... call logged (28/10/2014 14:56:58) xyz ..... call updated (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
insert into @callcentre
select '(29/10/2014 14:56:14) xyz ..... call logged (29/10/2014 14:56:58) xyz ..... call updated (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
insert into @callcentre
select '(30/10/2014 14:56:14) xyz ..... call logged (30/10/2014 14:56:58) xyz ..... call updated
output:
1) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910201'
2) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910201'
3) 28/10/2014 14:57:41, (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910201'
4) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910202'
5) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910202'
6) 28/10/2014 14:57:41, (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910202'
7) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910203'
8) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910203'
Thanks,
See this illustration
declare @callcentre table (comments varchar(max),lbiref varchar(200))
insert into @callcentre
select '(28/10/2014 14:56:14) xyz ..... call logged (28/10/2014 14:56:58) xyz ..... call updated (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
insert into @callcentre
select '(29/10/2014 14:56:14) xyz ..... call logged (29/10/2014 14:56:58) xyz ..... call updated (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
insert into @callcentre
select '(30/10/2014 14:56:14) xyz ..... call logged (30/10/2014 14:56:58) xyz ..... call updated','Vi2910203'
SELECT LEFT(p.u.value('.[1]','varchar(max)'),CHARINDEX(')',p.u.value('.[1]','varchar(max)'))-1) AS [Date],
'(' + p.u.value('.[1]','varchar(max)') AS comments,
lbiref
FROM
SELECT lbiref,CAST('<Root>' + STUFF(REPLACE(comments,'(','</Data><Data>'),1,7,'') + '</Data></Root>' AS XML) AS x
FROM @callcentre c
)t
CROSS APPLY x.nodes('/Root/Data')p(u)
and the output
Date comments lbiref
28/10/2014 14:56:14 (28/10/2014 14:56:14) xyz ..... call logged Vi2910201
28/10/2014 14:56:58 (28/10/2014 14:56:58) xyz ..... call updated Vi2910201
28/10/2014 14:57:41 (28/10/2014 14:57:41)xyz ..... call updated Vi2910201
29/10/2014 14:56:14 (29/10/2014 14:56:14) xyz ..... call logged Vi2910202
29/10/2014 14:56:58 (29/10/2014 14:56:58) xyz ..... call updated Vi2910202
29/10/2014 14:57:41 (29/10/2014 14:57:41)xyz ..... call updated Vi2910202
30/10/2014 14:56:14 (30/10/2014 14:56:14) xyz ..... call logged Vi2910203
30/10/2014 14:56:58 (30/10/2014 14:56:58) xyz ..... call updated Vi2910203
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
CallableStatement: how to get prepared call string?
How can I get the parameter string that is set via prepareCall() from a CallableStatement?
String call = "{call sp_irecord (?,?,?)}";
CallableStatement cs = connection.prepareCall(call);
//later, when 'call' is not known but cs:
String originalCall = csc.get???();
//how to get the call string from the callable statement?i don't mean the parameter names or values, i mean the string that you set with the prepareCall() method:
String call = "{call sp_irecord (?,?,?)}";
CallableStatement cs = connection.prepareCall(call);
System.out.println("Call string: "+cs.getCallString());with the method getCallString() (that i invented and that i'm looking for) should return the exact string. The output of the example above should be:
Call string: {call sp_irecord (?,?,?)} -
How to get a string or byte array representation of an Image/BufferedImage?
I have a java.awt.Image object that I want to transfer to a server application (.NET) through a http post request.
To do that I would like to encode the Image to jpeg format and convert it to a string or byte array to be able to send it in a way that the receiver application (.NET) could handle. So, I've tried to do like this.
private void send(Image image) {
int width = image.getWidth(null);
int height = image.getHeight(null);
try {
BufferedImage buffImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
ImageIcon imageIcon = new ImageIcon(image);
ImageObserver observer = imageIcon.getImageObserver();
buffImage.getGraphics().setColor(new Color(255, 255, 255));
buffImage.getGraphics().fillRect(0, 0, width, height);
buffImage.getGraphics().drawImage(imageIcon.getImage(), 0, 0, observer);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(stream);
jpeg.encode(buffImage);
URL url = new URL(/* my url... */);
URLConnection connection = url.openConnection();
String boundary = "--------" + Long.toHexString(System.currentTimeMillis());
connection.setRequestProperty("method", "POST");
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
String output = "--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"myImage\"; filename=\"myFilename.jpg\"\r\n"
+ "Content-Type: image/jpeg\r\n"
+ "Content-Transfer-Encoding: base64\r\n\r\n"
+ new String(stream.toByteArray())
+ "\r\n--" + boundary + "--\r\n";
connection.setDoOutput(true);
connection.getOutputStream().write(output.getBytes());
connection.connect();
} catch {
}This code works, but the image I get when I save it from the receiver application is distorted. The width and height is correct, but the content and colors are really weird. I tried to set different image types (first line inside the try-block), and this gave me different distorsions, but no image type gave me the correct image.
Maybe I should say that I can display the original Image object on screen correctly.
I also realized that the Image object is an instance of BufferedImage, so I thought I could skip the first six lines inside the try-block, but that doesn't help. This way I don't have to set the image type in the constructor, but the result still is color distorted.
Any ideas on how to get from an Image/BufferedImage to a string or byte array representation of the image in jpeg format?Here you go:
private static void send(BufferedImage image) throws Exception
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(image, "jpeg", byteArrayOutputStream);
byte[] imageByteArray = byteArrayOutputStream.toByteArray();
URL url = new URL("http://<host>:<port>");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStream outputStream = connection.getOutputStream();
outputStream.write(imageByteArray, 0, imageByteArray.length);
outputStream.close();
connection.connect();
// alternative to connect is to get & close the input stream
// connection.getInputStream().close();
} -
How to get rendered JSF page (send it as HTML email)
Hello,
I would like to send notification email in my application. Could you please help me to find a way how to get HTML result of JSF page as string-file-stream. Simply anything I could handle and use it as email body or attachment.
My use case: User click to button (raise a action) which change something in DB and confirmation.xhtml(.jsf) is shown to him to confirm that this action was succesful. And I would like to send notification email to all other users with this page (simplified version).
I need a something like String getJsfPage(String url) but I could not find anything in JSF API.
Thanks for any clue.quote gimbal2: +...now write the code to generate the email body...+
Thanks for reply...
Is that mean that I could not use already written code (confirmation.xhtml)? The beuty on JSF is that JSF parser take care about CSS styles, EL, templating (ui: ...), ... When anybody (administrators) wants to change how this email looks - just change this XHTML file.
How should I write email body? I thought about several way but nothing what looks good:
- I really dont want to use StringBuilder do build HTML.
- I dont want to write my own parser of .xhtml template (confirmation.xhtml).
- Write HTML (xml) template and parse it with XSLT transformation seems to me acceptable but complicated. Needs a special library to perform XSLT, complicated template service (future changes)
- JSP page, more-or-less the same problems like JSF page
The sad is that this email (html) body is quite small but highly dynamic (css, language of texts, logos...). -
How to get the name before @ in an email id
Hi All,
How can i get the name before '@' in an email id, for example if i have [email protected], how do i get 'abc' in my query result.
Thanksthinkingeye wrote:
Hi All,
How can i get the name before '@' in an email id, for example if i have [email protected], how do i get 'abc' in my query result.
Thankscombine INSTR() & SUBSTR() functions -
How can we test SCript before sending to recipient/
Hi ,
How can we test the script before sending the recipient.
Regards,
venkat.Hi,
you made your script in order to be use in a bussiness process. So you need to know each process, and then according to that do a sprecific action in the process. Ex: Sales Order creation can print a script.
Wich process is the script intended to?
Regards,
Pedr -
How to get the string's byte length?
I have some string,I want to get the string's byte length,how
can do it?
for example:
<cfoutput>#len('hihi,这是测试')#</cfoutput>
output is 9
I want to get the byte length is 14, how can i get it?
Thanks.>> Fair cop. I didn't realise that asc() returned the
codepoint rather than the
> actual character code.
>
> and what would be the difference?
Oh, sorry, whatever the term is (I'm crap with jargon). The
value returned
by asc() for those chars was only two bytes (ie: four hex
digits). I
didn't realise there was more to it than that, and that
2-byte value maps
to some other THREE byte value. I need to do some reading...
> that's what both cf & java counted as the length.
CHARACTER length, sure. No-one's disputing that. On the other
hand,
no-one's asking about it, either.
> by adding a BOM you've already effected the encoding,
which may or may not
> match the original. so you still don't know how many
bytes were in the original
> string.
[groan]
Yes, that's a reasonable strawman there. I was only putting
it in a file
so I could save it and check the number of bytes occupied by
the data.
Clearly... CLEARLY... the OP is not asking for a character
length of that
string. They've said as much.
I copy and pasted the string from their post, and used it as
a
demonstration of how "nine" is not the right answer for the
BYTE LENGTH of
that string. Whether or not the original string was UTF-8,
UTF-16 or
special-marmoset-encoding, it almost certainly was NOT in a
fictitious kind
encoding in which each of those particular characters only
occupied one
byte each, which would mean that "nine" is the correct answer
to the
question.
When I copied those characters from either the web browser
for from my
text-based news agent, notepad identified them (and rendered
them
correctly) as UTF-8, so I'm fairly confident they ARE UTF-8.
Of course
this could be down to some intermediary encoding (pasting
them in to the
original posting, for example, via some encoding-transforming
mechanism),
but Occam's Razor suggests the original question was from a
UTF-8 POV.
But maybe we should quit speculating and ask the OP. Unless
they've
buggered off in despair of how drawn out all this is getting.
For which I
would not blame them.
Adam -
How to erase personal info before sending a machine in for exchange?
I may have to return the iMac I just bought because of screen problems.
There's a lot of personal stuff on it already (mail account setup, photos, probably some saved website passwords) so I'm wondering if there's a quick and easy way to wipe out all the user data before sending the machine back to be swapped out?I just upgraded from an eMac to an iMac. In order to wipe the old drive I reinstalled the OS (10.4.11), which overwrites the whole drive. My understanding is that this actually writes zeros on unused disk space. I'm not sure if there are more sophisticated solutions for those concerned about someone recovering data from an erased drive.
When you reinstall you have a choice of quitting setup before creating any accounts or setting up a user account. If you're returning the machine it doesn't matter, as they're likely going to reinstall the OS again so the new owner of the refurbished machine can go through the setup themselves. -
How to get icloud email to send email with windows live mail
What setting do i need to use get icloud email to send email through winndows live mail. I can receive email
The settings for iCloud's servers are listed here:
http://support.apple.com/kb/HT4864
Maybe you are looking for
-
Hi all So I have lightroom on both my laptop and desktop and sync catalog through google drive. I have been working on the desktop all week on edits of high res scan in lightroom. Today i opened the program to find everything i have done for a week i
-
Different sp's in the same domain?
Is it possible to have an admin server that is 7.0 service pack 2 and one of the managed servers 7.0 service pack 4?
-
I am trying to speed up my video clip in imovie 09 but it doesnt give me the option to change the speed on my video adjustments clip tab..Help me please..
-
No Objects found! - Sotware components for Business System
Hello, I have changed the product assignment to the technical system after configuring the Business systems in IB. Then I am getting 'No Objects found!' in the 'Other Attributes' tab of Display Service -> Business System. Kindly do let me know How to
-
Zen 3 + Terminal server problem
Hi, We have 3 MS terminal server (1xNT, 1xWin2000 and 1xWin2003) machines that are attached to our novell network all of which we have the same problem with Zen delivered applications. Applications will launch ok unless we use Zen application meterin