473,804 Members | 4,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception: Can not issue SELECT via executeUpdate!

61 New Member
Hai to all,

Now i'm trying to export Mysql table to a file By using the

following program...

itz sucessfully compiled... but it throws the above Exception..

[HTML]
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.sql.*;
  3. public class ExportData {
  4. public static void main(String args[]) {
  5.         String Driver;
  6.         Statement stmt; 
  7.          ResultSet rs; 
  8.  
  9.          Driver = "com.mysql.jdbc.Driver";
  10.          Connection con = null;
  11.  
  12. try {
  13. Class.forName(Driver);
  14. con = DriverManager.getConnection("jdbc:mysql://192.168.0.01/senthil","root","");
  15.  if(!con.isClosed()){
  16. System.out.println("Successfully connected to MySQL DataBase \n");
  17.       stmt = con.createStatement(); 
  18.       String filename = "C:/2.txt";
  19.       String tablename = "employees";
  20.       String sql;
  21. stmt.executeUpdate("SELECT * INTO OUTFILE \"" + filename + "\" FROM " + tablename);
  22.   }
  23. } catch(Exception e) {
  24.  System.err.println("Exception: " + e.getMessage());
  25.     } 
  26. finally {
  27.       try {
  28.         if(con != null)
  29.           con.close();
  30.       } catch(SQLException e) {}
  31.  }
  32. }
  33. }
[/HTML]

Can anyone plzz help me....

thanks and regards..
senthil
Feb 9 '07 #1
6 13832
r035198x
13,262 MVP
Hai to all,

Now i'm trying to export Mysql table to a file By using the

following program...

itz sucessfully compiled... but it throws the above Exception..

[HTML]
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.sql.*;
  3. public class ExportData {
  4. public static void main(String args[]) {
  5. String Driver;
  6. Statement stmt; 
  7. ResultSet rs; 
  8.  
  9. Driver = "com.mysql.jdbc.Driver";
  10. Connection con = null;
  11.  
  12. try {
  13. Class.forName(Driver);
  14. con = DriverManager.getConnection("jdbc:mysql://192.168.0.01/senthil","root","");
  15. if(!con.isClosed()){
  16. System.out.println("Successfully connected to MySQL DataBase \n");
  17. stmt = con.createStatement(); 
  18. String filename = "C:/2.txt";
  19. String tablename = "employees";
  20. String sql;
  21. stmt.executeUpdate("SELECT * INTO OUTFILE \"" + filename + "\" FROM " + tablename);
  22. }
  23. } catch(Exception e) {
  24. System.err.println("Exception: " + e.getMessage());
  25. finally {
  26. try {
  27. if(con != null)
  28. con.close();
  29. } catch(SQLException e) {}
  30. }
  31. }
  32. }
[/HTML]

Can anyone plzz help me....

thanks and regards..
senthil
You use executeQuery for select. You re doing it wrong any way. Read the data from the db record by record and write to the file using BufferedWriter and FileReader.
Feb 9 '07 #2
dmjpro
2,476 Top Contributor
hello r035198x
why r u telling to do using file operation...
i wondering .....
plz tell me u suggestion in detail ............
Feb 12 '07 #3
hirak1984
316 Contributor
well executeUpdate is for operations such as insert,update etc.

for select we use executeQuery.
and regarding file operation,It is up to me whether I write the output in file or console.
Feb 12 '07 #4
r035198x
13,262 MVP
hello r035198x
why r u telling to do using file operation...
i wondering .....
plz tell me u suggestion in detail ............
The reading of data is done using the jdbc and the sql is done using executeQuery in this case which returns a resultset object. That part is fine. In this case the OP used the wrong command, executeUpdate, which you use to modify data in the table and you have to provide the new data that you want to mofify with. That's why the compiler complained. With executeQuery, you query the database and ask for data which you are given through a resultset object. To write that data to a file, you do not use sql like the OP was trying to there but instead you use a FileWriter and wrap it with a BufferedWriter like this

Expand|Select|Wrap|Line Numbers
  1. BufferedWriter writer = new BufferedWriter(new FileWriter("filename.txt"));
and then do something like
Expand|Select|Wrap|Line Numbers
  1. writer.write(resultset.getString("columnName"));
Feb 12 '07 #5
dmjpro
2,476 Top Contributor
sorry my mistake .......


i didn't see that command ......

u r right ....
what i am fool
Feb 12 '07 #6
r035198x
13,262 MVP
sorry my mistake .......


i didn't see that command ......

u r right ....
what i am fool
Don't be too hard on yourself. We all miss important parts of code at one point or another. That's the reason we keep company.
Feb 12 '07 #7

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

Similar topics

0
1683
by: Oliver | last post by:
Hello, (I posted about this a few weeks agao, but got no response. I've tried some more stuff since then...) I’ve written a Visual basic .NET program that need to create a new .DBF file based upon two existing .DBF files. The program generates an “Index not found” exception when I attempt to create the new file using the SQL- SELECT … INTO command. However, this problem exists ONLY when run on a computer that is a member of
15
2259
by: David | last post by:
Hi, I have built a web application that will be a very high profile application. We had tested it, demonstrated it and shown that it all works. On a dress rehearsal run through, it failed spectacularly. I was so embarrassed and felt like killing the person that made it fail. However, when it goes live, IT MUST NOT FAIL. The system has a backoffice system that takes an excel spreadsheet from the
6
4056
by: Steve Long | last post by:
Help, I'm running VS.NET 2003 and when I try to start my application, I get the "unhandled exception" dialog instead of the IDE highlighting the offending line of code. The problem appears to be instantiating a particular class in my project but the dialog doesn't tell me what code in the class is causing the problem (and it a large class). How can I get the IDE to take me to the offending line of code? If I put this line in my...
5
2472
by: CyberLotus | last post by:
Hi, I've created a web application and through this I want to import Excel data to database. Following is the code that I've written, ******************************************************************* string fileLocation = txtboxFileName.Text.ToString(); string sheetName = "Import"; string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
4
4811
by: technocrat | last post by:
I am trying to update a million rows in a table and doing this reading from a file which has the record pkids and constructing a preparedstatemtn with that pkid and adding it to the batch... count is the recordnumber read from the file... so for every count the st is added to the batch.....since for every record read from the file has a update statement(st)... st.setString(1, arg1); st.setString(2, arg2); st.setString(3, arg3);
1
3376
by: ajos | last post by:
hi evrybdy, the problem is:- i had this running before in jsp but when i changed the jsp page using struts tags there occoured a problem... when i enter values in the 2 text boxes and click enter an exception occours which is- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request.
5
2349
by: iamdennisthomas | last post by:
Hi Guys i was developing a action servlet which is actulally getting the data from a form and putting it in the db but while executing i am getting a null pointer exception /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.radesan.struts.action; import java.sql.*; import javax.servlet.http.HttpServletRequest;
4
1271
by: prisesh26 | last post by:
hi, iam getting exception (for duplicate key )displayed when i do ps.executeUpdate(); i ll get this duplicate key exception rarely. but i dont want the whole eception to be displayed in the console. instead i want to display in single line. i want to display in single readable line i am catching the exception but still before it comes to catch section it is throwing the exception stack trace in my console. how to control...
2
3281
by: bednarz.thomas | last post by:
I have the following business Object(s): public class ParentObject { public ParentObject(string somestring) { ...- } ....
0
9706
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9579
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
10577
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
10320
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
6853
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();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
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
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.