473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to SELECT INTO OUTFILE with header labels of the fields?

126 64KB
Expand|Select|Wrap|Line Numbers
  1. select '"sl"','"quantity"','"price"'
  2.  union all select sl,quantity,price into outfile 'C:/file.txt' fields terminated by ',' 
  3. lines terminated by '\r\n' from table
the above query works perfect at command line prompt but when i use as below i get error at the quotes used near sl,quantity and price that is it does not accept '"sl"','"quantity"','"price"' can someone help me please


Expand|Select|Wrap|Line Numbers
  1. Statement st = con.createStatement();
  2. String query = "select '"sl"','"quantity"','"price"' 
  3. union all select sl,quantity,price into
  4.  outfile 'C:/file.txt' fields terminated by ',' 
  5. lines terminated by '\r\n' from "+table+"";
  6. ResultSet rs = st.executeQuery(query);   
Apr 18 '13 #1
3 1699
Rabbit
12,516 Expert Mod 8TB
You need to escape your double quotes.
Apr 18 '13 #2
PreethiGowri
126 64KB
it works now thank you:)
Apr 18 '13 #3
r035198x
13,262 8TB
Use a PreparedStatement not a Statement and it will not only quote for you but also prevent SQL injection.
Apr 18 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tom Pope | last post by:
Is there a way to have the field descriptions put into an outfile? When I do a Select * from data, the display shows the field names, however when I do the select * into outfile /tmp/test.txt the...
0
by: Luke Airig | last post by:
I am using the Saxon engine and I have an xml file that contains batches of records. Each batch starts with a header record and the associated detail records immediately follow each header. There...
4
by: Chris | last post by:
I'm trying to automate the process of uploading files from a client to a webserver. I know that this can't be done by setting the value of the file field in an html form. So far, the plan is to...
2
by: Bruce D | last post by:
I have query that I export into a file using the "outfile" syntax. I can use the following lines of code to create a delimited file but I want to know if I can create a fixed length file? Any...
3
by: shumaker | last post by:
I was curious... Is there a way to select distinct on a combination of some fields and the for each record returned also get the other fields of an arbitrarily chosen record matching the fields...
6
by: Chuck | last post by:
I have a report with three columns, accross then down, and two groups. Currently the group headers are only one column wide and appear in the left hand column. How can I make the group header be...
0
by: cedoucette | last post by:
I just wrote code to support sortable columns in a datagrid. It seems to work fine; but, it doesn't look right. The problem is that I have a generic style for links and a different style for the...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
5
by: Mel | last post by:
I created a header that adjusts with the size of the browser windows. How do I place labels in the header section so they also maintain their position when the window is resized? One of the labels...
10
by: KaliKraft | last post by:
I have a tblWork that has a dozen fields in it. It tracks hours worked for 2 employees at a time. - fldDriverID - fldDriverHours - fldHelperID - fldHelperHours It also has a date field...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.