To fatch the data from sql to excel ??? any idea....
dear all,
my problem is - i want to retrive the data from sql server to excel sheet... can any one suggest the idea what to do ???
thanks.
You can open two connections. One to SQL Server (you can use a thin or JDBC-ODBC bridge), the other to your Excel spreadsheet using the JDBC-ODBC bridge. You could query the SQL Server database, massage and format your data, then write it to Excel. Excel works with a very limited set of SQL. Here is a program from a post by Tim Vickers that others sounded happy to have. I'm reposting here for your convenience. I have not personally run this program, so please use it at your own risk.
import java.sql.*;
import java.io.*;
import java.util.*;
import java.text.*;
* Name: Excel.java
* Purpose: To demonstrate how to use ODBC and Excel to create
* a table,
* insert data into it, and select it back out.
* Version: Developed using JDK 1.3, but also works with JDK
* 1.2.2
* Instructions:
* 1) Create a new Excel spreadsheet
* 2) Create a new ODBC data source that points to this
* spreadsheet
* a) Go to Control Panel
* b) Open "ODBC Data sources (32-bit) (wording may be
* slightly
* different for different platforms)
* c) Under "User DSN" tab, press "Add" button
* d) Select the "Microsoft Excel Driver (*.xls)" and
* press
* "Finish" button
* e) Enter "Data Source Name" of "TestExcel"
* f) Press "Select Workbook" button
* g) Locate and select the spreadsheet you created in
* Step 1
* h) Unselect the "Read Only" checkbox
* i) Press "Ok" button
* 3) Compile and run Excel.java
* 4) Open Excel spreadsheet and you will find a newly
* created
* sheet, GOOD_DAY, with three rows of data.
* Notes:
* If you want to select data from a spreadsheet that was
* NOT
* created via JDBC-ODBC (i.e. you entered data manually
* into
* a spreadsheet and want to select it out), you must
* reference
* the sheet name as "[sheetname$]".
* When you create the table and insert the data using
* Java, you
* must reference the sheet name as "sheetname".
* Also, do not have the spreadsheet open when you are
* running
* the program. You can get locking conflicts.
public class Excel {
public Excel() {
setDefaults();
private static void m(String pMessage) {
System.out.println(pMessage);
private void setDefaults() {
setDriver("sun.jdbc.odbc.JdbcOdbcDriver");
setUrl("jdbc:odbc");
// ODBC data source named "TestExcel" defined from
Control Panel
setDataSource("TestExcel");
setTableName("GOOD_DAY");
public void openDatabase() {
String lConnectStr = getUrl()+":"+getDataSource();
try {
Class.forName(getDriver());
gConnection = DriverManager.getConnection(lConnectStr);
catch (Exception e) {
m("openDatabase(): "+e.getMessage());
private void closeDatabase() {
try {
getConnection().close();
catch (Exception e) {
m("closeDatabase(): "+e.getMessage());
private void createTable() {
m("createTable() begin");
Statement lStat = null;
try {
lStat = getConnection().createStatement();
lStat.execute("CREATE TABLE "+getTableName()+" ("
+" ID INTEGER"
+" ,NAME VARCHAR"
+")");
catch (Exception e) {
m("createTable(): "+e.getMessage());
m("createTable() end");
private void doInsert() {
m("doInsert() begin");
Statement lStat = null;
try {
lStat = getConnection().createStatement();
lStat.executeUpdate("INSERT INTO "
+getTableName()+"(ID,NAME) VALUES
(10,'KANGAROO')");
lStat.executeUpdate("INSERT INTO "
+getTableName()+"(ID,NAME) VALUES (20,'KOALA')");
lStat.executeUpdate("INSERT INTO "
+getTableName()+"(ID,NAME) VALUES (30,'PAUL
HOGAN')");
lStat.close();
catch (Exception e) {
m("doInsert(): "+e.getMessage());
m("doInsert() end");
private void doQuery() {
m("doQuery() begin");
try {
Statement lStat = getConnection().createStatement();
ResultSet lRes = lStat.executeQuery(
"SELECT * FROM "+getTableName()
ResultSetMetaData lMeta = lRes.getMetaData();
// print out the column headers separated by commas
for (int i = 1; i <= lMeta.getColumnCount(); ++i) {
if (i > 1)
System.out.print(", ");
String lValue = lMeta.getColumnName(i);
System.out.print(lValue);
System.out.println("");
// print out the data separated by commas
while (lRes.next()) {
for (int i=1; i<=lMeta.getColumnCount(); ++i) {
if (i > 1)
System.out.print(", ");
String lValue = lRes.getString(i);
System.out.print(lValue);
System.out.println("");
lRes.close();
lStat.close();
catch (Exception e) {
m("doQuery(): "+e.getMessage());
m("doQuery() end");
private void run() {
openDatabase();
createTable();
doInsert();
doQuery();
closeDatabase();
public static void main(String args[]) {
m("main() begin");
Excel lExcel = new Excel();
lExcel.run();
m("main() end");
System.exit(0);
public void setTableName(String pValue) {
gTableName = pValue;
public String getTableName() {
return(gTableName);
public void setSql(String pValue) {
gSql = pValue;
public String getSql() {
return(gSql);
public Connection getConnection() {
return(gConnection);
public String getDataSource() {
return(gDataSource);
public void setDataSource(String pValue) {
gDataSource = pValue;
public void setDriver(String pValue) {
gDriver = pValue;
public void setUrl(String pValue) {
gUrl = pValue;
public String getDriver() {
return (gDriver);
public String getUrl() {
return (gUrl);
private Connection
gConnection = null
private String
gDataSource = null
,gTableName = null
,gSql = null
,gDriver = null
,gUrl = null
}
Similar Messages
-
Can we update the data from SSRS report to any database ?
Hi Team,
Greetings !!!!
Can we update the data from SSRS report to any database ?
Thanks,
Anand Gavle.Nope SSRS doesnt have write back options. Its just a reporting tool
However one thing you can do is to link a webpage from SSRS report and do the changes through it
SSRS has the ability to navigate to web page through which you can capture any data inputs from users and save it to your db.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Transferring data from SQL to Excel
Getting an error emssage on Executing following command "EXEC proc_generate_excel_with_columns4 '[servername]', '[tablename]','[path of the file]'"
From SQL Server to Excel? There are so many ways you can do it!!
For one thing, you can run VBA code.
Sub ADOExcelSQLServer()
' Carl SQL Server Connection
' FOR THIS CODE TO WORK
' In VBE you need to go Tools References and check Microsoft Active X Data Objects 2.x library
Dim Cn As ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
Dim SQLStr As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Server_Name = "Excel-PC\SQLEXPRESS" ' Enter your server name here
Database_Name = "Northwind" ' Enter your database name here
User_ID = "" ' enter your user ID here
Password = "" ' Enter your password here
SQLStr = "SELECT * FROM dbo.Orders" ' Enter your SQL here
Set Cn = New ADODB.Connection
Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"
rs.Open SQLStr, Cn, adOpenStatic
' Dump to spreadsheet
With Worksheets("sheet1").Range("a1:z500") ' Enter your sheet name and range here
.ClearContents
.CopyFromRecordset rs
End With
' Tidy up
rs.Close
Set rs = Nothing
Cn.Close
Set Cn = Nothing
End Sub
Or
Sub Create_Connectionstring()
'# creates a connection string... #
'# References need to be set in the VBE to the following #
'# reference libraries:- #
'# Microsoft ActiveX Data Objects x.x Library #
'# Microsoft OLE DB Service Component 1.0 Type Library #
Dim objDL As MSDASC.DataLinks
Dim cnt As ADODB.Connection
Dim stConnect As String 'Instantiate the objects.
Set objDL = New MSDASC.DataLinks
Set cnt = New ADODB.Connection
On Error GoTo Error_Handling 'Show the Data-link wizard
stConnect = objDL.PromptNew 'Test the connection.
cnt.Open stConnect 'Print the string to the VBE Immediate Window.
Debug.Print stConnect 'Release the objects from memory.
exitHere:
cnt.Close
Set cnt = Nothing
Set objDL = Nothing
Exit Sub
Error_Handling: 'If the user cancel the operation.
If Err.Number = 91 Then
Resume exitHere
End If
End Sub
Sub ADOExcelSQLServer()
Dim Cn As ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
Dim SQLStr As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Server_Name = "LAPTOP\SQL_EXPRESS" ' Enter your server name here
Database_Name = "Northwind" ' Enter your database name here
User_ID = "" ' enter your user ID here
Password = "" ' Enter your password here
SQLStr = "SELECT * FROM Orders" ' Enter your SQL here
Set Cn = New ADODB.Connection
Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"
rs.Open SQLStr, Cn, adOpenStatic
With Worksheets("Sheet1").Range("A2:Z500")
.ClearContents
.CopyFromRecordset rs
End With
rs.Close
Set rs = Nothing
Cn.Close
Set Cn = Nothing
End Sub
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it. -
Extract the data from SQL Server and Import into Oracle
Hi,
I would like to run a daily job that will export the table data from SQL server table (it will be only one or two table) and Import back into Oracle table (it might one or two table tables).
Could you please guide me that how can i do this using either sql server or oracle?
We have oracle 9.2 and sql server 2005.
Normally i do from flat file which is generated by source destination nand i dump into oracle using sql*loader but this time I have to directly extract/export the data from MS Sql server and load into Oracle table, mostly it will reload so i might doing any massaging data during the load.
If you show me the detail approach, it will be really appreciated.
I have access to Sql server but i don't how to use sql server to do this or using oracle as a daily job even becuase have to schedule the job for this as it will be a daily job.
Thanks,
poratipsUnless you can find an open source ODBC driver for SQL Server that runs on Solaris (and I wouldn't be overly hopeful there) Heterogeneous Services would require that you license something-- a third party ODBC driver, a new Oracle instance, or an Oracle Transparent Gateway.
As I stated below, you could certainly use SQL Server's ETL tool, DTS. Oracle's ETL tools would require additional licensing since you're just on 9.2. You could also write a small application (Java or otherwise) that connected to both databases and transferred the data. If you're particularly enterprising, you could load the SQL Server Type 4 JDBC driver into Oracle's JVM and write a Java stored procedure that connected to the SQL Server database via JDBC, but that's a pretty convoluted approach.
Justin -
Need to fatch the data from sqlserver to Oracle DATABASE ;not migration
Hello,
What is the easiest method to insert/refresh data into Oracle Tables from SQLSERVER 2005 table.Do I need ODBC connection and how it works in the PL/SQL to create the connection and fetch the data from sqlserver.
Thanks,
SarabmannI need to fetch from ORACLE back-end ,for example I want to install the mechanism at the back-end server where if I write stored procedure and call this link which enable me to fetch the data from sqlserver.
Environment:- Linux as OS
Oracle 10G as a Database -
Copy the data from Sql Server to edirectory using java
Hi ,
I am new to e directory.I don't know how it works.Can some one assist
me on this ,I have to extract data from SQL Server and update these
data in edirectory.This is needs to be done using java.
If any one can provide me the sample code or please suggest how to
proceed .
Thanks in advance
dukewarm
dukewarm's Profile: http://forums.novell.com/member.php?userid=53430
View this thread: http://forums.novell.com/showthread.php?t=373051dukewarm;1792481 Wrote:
> Hi ,
>
> I am new to e directory.I don't know how it works.Can some one assist
> me on this ,I have to extract data from SQL Server and update these
> data in edirectory.This is needs to be done using java.
>
> If any one can provide me the sample code or please suggest how to
> proceed .
>
> Thanks in advance
Read the values from SQL server and use LDAP to update the data in
eDirectory.
Thomas
thsundel
thsundel's Profile: http://forums.novell.com/member.php?userid=128
View this thread: http://forums.novell.com/showthread.php?t=373051 -
Exporting the datas from jsp to excel spreadsheet
Hi:
I would like to know how to publish the datas from a jsp page to an excel spreadsheet . Is there ay software I've to use or an API.
and how to use it.
Would appreciate the replies.
Thanks.OK. Lets say you query a DB and get back a results set with 2 rows from a DB table where each row has 4 columns (all columns are string types). Here is some code that should give you the idea, note I didn't compile it so you'll have to work out the bugs.
Example data:
col1 col2 col3 col4
a1 a2 a3 a4
b1 b2 b3 b4
public void printFile(ResultSet rs, File file) throws Exception {
FileWriter fout = null;
int index;
final String DELIM = "\t"; // tab delimiter, use the character you prefer
final String NL = System.getProperty("line.separator", "\n")
try {
fout = new FileWriter(file);
while (rs.next()) {
index = 1;
fout.write(rs.getString(index++) + DELIM + rs.getString(index++) + DELIM
rs.getString(index++) + DELIM +rs.getString(index++) + NL);
} catch(Exception e) {
e.printStackTrace();
throw e;
} finally {
try { fout.close(); } catch (Exception e) {} // do nothing -
How to export the data from table to excel sheet
hi experts i have some problem am trying to export the data fro table to Excel sheet in the view controller i have created one button wit public void onActionCLEAR(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionCLEAR(ServerEvent)
//wdContext.nodeBapi_Salesorder_Getlist_Input().
//wdContext.nodeBapi_Salesorder_Getlist_Input().invalidate();
//@@end
//@@begin javadoc:onActionExporToExcel(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionExporToExcel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionExporToExcel(ServerEvent)
try{
FileOutputStream fos=new FileOutputStream("Test.xls");
PrintStream ps=new PrintStream(fos);
ps.println("<html><body><table border=1>");
int size=wdContext.nodeBapi_Salesorder_Getlist_Input().size();
Iterator attributes=wdContext.getNodeInfo().iterateAttributes();
ps.println("<tr>");
while(attributes.hasNext()){
ps.println("<th>");
DataAttributeInfo attrName=(DataAttributeInfo)attributes.next();
ps.println(attrName.getName());
ps.println("</th>");
ps.println("</tr>");
for(int i=0; i<wdContext.nodeBapi_Salesorder_Getlist_Input().size();i++)
attributes=wdContext.getNodeInfo().iterateAttributes();
ps.println("<tr>");
IWDNodeElement ele=wdContext.getElementAt(i);
while(attributes.hasNext()){
ps.println("<td>");
DataAttributeInfo attrName=(DataAttributeInfo)attributes.next();
ps.println(""+ele.getAttributeAsText(attrName.getName()));
ps.println("</td>");
ps.println("</tr>");
ps.println("</table></body></html>");
ps.flush();
ps.close();
fos.close();
catch(Exception e){
wdComponentAPI.getMessageManager().reportException(e.getMessage(), false);
finally{
//return("Test.xls") ;
//@@end
}h action and i have return the code
its running sucessfully but am not able to perform the action plz help meHi,
You shouldn't use DataAttributeInfo as it is an internal object, if I'm correct.
Use IWDAttributeInfo instead of DataAttributeInfo and it should work
(See also API doc of IWDNodeInfo.iterateAttributes() at http://help.sap.com/javadocs/nwce/ce711sp02/wdr/com.sap.wdr/com/sap/tc/webdynpro/progmodel/api/IWDNodeInfo.html#iterateAttributes())
Cheers,
Robin -
Is there any method to export the data from oracle 10g in any format !!!!!
is there any methods to export the data from oracle 10g in the format of excel or csc or txt or anyother. i already downloaded the sql developer tool but it only exports the data of upto one lakh rows ,but i have two tables of more than 3 lakh and 10 lakh rows respectively.for this i used 'where' command to break the file through sql developer but that didnt work
plz help me out if any thing possible
i need to again import this data into microsoft sql if there is any direct method plz let me know
its urgent
Message was edited by:
user628031
Message was edited by:
user628031Take a look at DUMP_CSV function by Tom Kyte.
-
Issue to export data from sql to excel
I have MS SQL 2008 Developer version and visual studio 2008. I'm using SSIS Import and Export Wizard on the VS2008 to create a simple package to export data from a table using a sql query to excel file (.xlsx), but I got the following
error messages:
[Destination - Query [37]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E21.
[Destination - Query [37]] Error: Cannot create an OLE DB accessor. Verify that the column metadata is valid.
[SSIS.Pipeline] Error: component "Destination - Query" (37) failed the pre-execute phase and returned error code 0xC0202025.
The SQL query is
SELECT [BusinessEntityID]
,[PersonType]
,[NameStyle]
,[Title]
,[FirstName]
,[MiddleName]
,[LastName]
FROM [AdventureWorks2008].[Person].[Person]
Any help will be appreciated. Thanks.
A Fan of SSIS, SSRS and SSASOr another way is to save the package created by Export Import wizard, open it in BIDS and add a Derived column task before the Excel destination to do explicit casting of the columns to your required unicode datatypes.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Procedure/batch file to export data from sql to excel(predefined path)
Hi,
I have countries, sites, states tables (total 3) in database (i have user id and password to connect to this database).
every week i need to extract data from these tables into excel files and i need to save those in shared drive for team use.
Currently i am connecting to database every time running sql query and manually exporting that latest data to excel and saving that as excel files in (G:\team\common\) folder with specific name.
output format should be : excel (.xls)
file names should - countries.xls,sites.xls,states.xls
server name : ap21
output location : G:\team\common\ ( G is shared drive).
i heard that we could create batch file to do this task and also we could use oracle procedure to do this task. but not sure which one is the best option.
could you please guide me what is the option and also help me with technical stuff to do this task.Hello,
output format should be : excel (.xls)Do you really want to create .xls files? This is not easy to do because it is a proprietary (MS) binary format. You should consider other formats like .csv or .xlsx. Follow the link in the previous answer how to generate them.
file names should ...The name of the files does not matter, you are free to name them as you like.
server name : ap21
output location : G:\team\common\ ( G is shared drive).You can write the file generated in the database only to directories that are accessible from the db as Oracle Directories. You could mount the shared drive to the db server, but it might be better to write the output to a server directory and then transfer them to the shared drive with OS-copy command or FTP.
i heard that we could create batch file to do this task and also we could use oracle procedure to do this task. but not sure which one is the best option.I would use Oracle Scheduler to execute a PL/SQL procedure to generate the files and then a OS-batch file to transfer them. You can use the Scheduler to execute the batch file too, see {message:id=3895983}.
Regards
Marcus -
Fetch the data from sql server table to array
In the following script i am fetching the servers details from text file. Please anyone help me to get the same information from sql server database table. with using this query
"SELECT DISTINCT [server_name]
FROM
Servers] where
Status='1'"
$ServerName =Get-Content "c:\servers\servers.txt"
foreach ($Server in $ServerName) {
if (test-Connection -ComputerName $Server -Count 4 -Delay 2 -Quiet ) {
write-output "$Server is alive and Pinging `n"
} else {
Write-output "TXUE $Server seems dead not pinging"i have tested it is not working..
=@"
SELECT DISTINCT [server_name] FROM Servers] where Status='1'
$connection
=new-objectsystem.data.sqlclient.sqlconnection(
"Data Source=xxx;Initial Catalog=xxx;Integrated Security=SSPI;”)
$adapter
=new-objectsystem.data.sqlclient.sqldataadapter($query,
$connection)
$table
=new-objectsystem.data.datatable
$adapter
.Fill($table)
| out-null
$compArray
=@($table)
##### Script Starts Here ######
foreach($Serverin$ServerName)
if(test-Connection-ComputerName$Server-Count4
-Delay2
-Quiet)
write-output"$Server
is alive and Pinging `n"
else{
$query -
SQL Interface - Error in Loading the data from SQL data source
Hello,
We have been using SQl data source for loading the dimensions and the data for so many years. Even using Essbase 11.1.1.0, it's been quite a while (more than one year). For the past few days,we are getting the below error when trying to load the data.
[Mon Jan 10 11:02:56 2011]Local/{App Name}/{DB Name}/{User Id}/Info(1021013)
ODBC Layer Error: [S1000] ==> [[DataDirect][ODBC DB2 Wire Protocol driver][UDB DB2 for Windows, UNIX, and Linux]CURSOR IDENTIFIED IN FETCH OR CLOSE STATEMENT
IS NOT OPEN (DIAG INFO: ).]
[Mon Jan 10 11:02:56 2011]Local/{App Name}/{DB Name}/{User Id}/Info(1021014)
ODBC Layer Error: Native Error code [4294966795]
[Mon Jan 10 11:02:56 2011]Local/{App Name}/{DB Name}/{User Id}/Error(1021001)
Failed to Establish Connection With SQL Database Server. See log for more information
[Mon Jan 10 11:02:56 2011]Local/{App Name}/{DB Name}/{User Id}/Error(1003050)
Data Load Transaction Aborted With Error [7]
[Mon Jan 10 11:02:56 2011]Local/{App Name}///Info(1013214)
Clear Active on User [Olapadm] Instance [1]
Interestingly, after the job fails thru our batch scheduler environment, when I run the same script that's being used in the batch scheduler, the job completes successfully.
Also, this is first time, I saw this kind of error message.
Appreciate any help or any suggestions to find a resolution. Thanks,Hii Priya,
The reasons may be the file is open, the format/flatfile structure is not correct, the mapping/transfer structure may not be correct, presence of invalid characters/data inconsistency in the file, etc.
Check if the flatfile in .CSV format.
You have to save it in .CSV format for the flatfile loading to work.
Also check the connection issues between source system and BW or sometimes may be due to inactive update rules.
Refer
error 1
Find out the actual reason and let us know.
Hope this helps.
Regards,
Raghu. -
Can we get the data from list without using any change event...
It is possible to get the current data from list without passing events?...
Thanks in advance,
senthil.Can you get what you want by accessing the selectedItem/selectedItems and selectedIndex/selectedIndices properties?
-
Help!
Hello Mikeytsmith
Check out the article below for troubleshooting the issue of activating FaceTime for Mac.
FaceTime, Game Center, Messages: Troubleshooting sign in issues
http://support.apple.com/kb/TS3970
Thanks for using Apple Support Communities.
Regards,
-Norm G.
Maybe you are looking for
-
Best way to index portal content
Hi all, I am searching for a nice way to index the content of the portal. Using the standard functionality (http://help.sap.com/saphelp_nw70ehp1/helpdata/en/46/9d1405fa743ef0e10000000a1553f7/frameset.htm) does not lead to sufficient results, since al
-
Computer dead (sbod) after losing webDAV connection
_The scenario:_ To not have to put the memory card of my mobile (Nokia E70) into a card reader, use a cable or transfer several 100 MB using Bluetooth, I am using Apache (raccoon) on the mobile to supply a WebDAV service and connect my iMac 2.16 OSX
-
Why does iPhoto delete my photos I have deleted off my memory card?
I have an 8 gb memory card for my camera. Sometimes I want to show pictures to people off my camera, so I don't delete all my photos off the memory card. I pick and choose. Recently, I was looking through iPhoto at old events and saw that the picture
-
ECC 6.0 SR3 Master Installation
I've downloaded the latest version ERP 6 (SR3), the master installation BS_2005_SR3_SAP_Installation_Master (DVD label D51033511). When execute sapinst the menus for ERP installation only shows the options : RAPID CONFIGURATION and SOFTWARE LIFE CYC
-
When I try to load an email, the following message appears: Cannot get mail/the connection to the server failed. After I click ok , then things work fine until the next time when the process starts over. I have tried resetting , but that hasn't wor