473,386 Members | 1,815 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,386 software developers and data experts.

Exception: Can not issue SELECT via executeUpdate!

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 13800
r035198x
13,262 8TB
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 2GB
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 100+
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 8TB
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 2GB
sorry my mistake .......


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

u r right ....
what i am fool
Feb 12 '07 #6
r035198x
13,262 8TB
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
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...
15
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...
6
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...
5
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, ...
4
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......
1
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...
5
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...
4
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...
2
by: bednarz.thomas | last post by:
I have the following business Object(s): public class ParentObject { public ParentObject(string somestring) { ...- } ....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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...

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.