473,669 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

126 New Member
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"','"quanti ty"','"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 1706
Rabbit
12,516 Recognized Expert Moderator MVP
You need to escape your double quotes.
Apr 18 '13 #2
PreethiGowri
126 New Member
it works now thank you:)
Apr 18 '13 #3
r035198x
13,262 MVP
Use a PreparedStateme nt 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
3266
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 field names are not in the file. Thanks for the help Tom
0
1549
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 can be multiple batches in a single file, each batch indicated by a new header. I need to create a tab-delimited output file that appends all of the header record fields in front of each associated detail record within the same batch. The...
4
4548
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 mimic the upload form by sending an http request to the server. I can do this without the file upload no problem, but I can't figure out how to include the file as well. Can anyone please help? Chris
2
3037
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 ideas? delimited file: Select GivenName, Surname, Address, City, State, ZipCode into outfile 'xx.csv' fields terminated by ',' lines terminated by '\r\n' from kbm where zipcode = '12345'
3
3732
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 in the distinct record. For example, if I have a select distinct on say three fields: SELECT DISTINCT Code1, Code2, Code3 but the table also has other fields, maybe Foo1 and Foo2, and I want Foo1 and Foo2 to also be displayed. Since there may...
6
38287
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 centered accross all columns? Chuck ....
0
2618
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 header row - and they conflict. The sortable column apparently uses the generic style for <a> elements and the rest of the header uses "headerRow". Can anyone tell me how to get consistent styles for each column in my datagrid header?
22
12466
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=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient moConn.Mode = adModeReadWrite' or using default...same result
5
2380
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 is constant but the rest will be entered programmatically, for example, the users name, their company, city, state and zip. My example code: <body> <form id="form1" runat="server">
10
1864
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 (fldDate) and a key to the ticket the work was performed on (fldTicketID). So I assign the driver and the hours worked (1,15h) same for helper (1,13h)
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8588
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.