Need Help writing CLOB file

I'm trying to write a servlet that receives a file upload and
inserts the file into a CLOB in Oracle. Taking it one step at a
time. I used the O'Reilly classes for file upload to receive the
file and save it to disk. The next step of reading the file and
saving it in Oracle is where things don't seem to work.
Basically, I open a connection to Oracle. Create a new row in my
table. Select the CLOB column from the table to open the stream,
then try reading the file and writing it to the stream.
When I look at my table, I see that the row has been inserted,
but the CLOB column is null.
I'm trying to write this for eventual use in receiving
XMLdocuments into our database for processing. So if anyone has
a better way of uploading the files directly into the database
over the net, I'd appreciate it.
My code follows:
// Copyright (c) 2000 CPCC
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
import java.text.*;
import com.oreilly.servlet.multipart.*;
* A Class class.
* <P>
* @author Rivera, Maynard
public class UpLoad extends HttpServlet {
private File dir;
private String username = "mrr";
private String password = "auction";
private String thinConn
= "jdbc:oracle:thin:@192.1.100.6:1526:N";
private Connection cn = null;
Statement stmt;
private void OpenConnection (HttpServletResponse response)
throws SQLException, IOException {
try {
//Connect with the Thin Driver
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver ());
cn = DriverManager.getConnection (thinConn, username,
password);
cn.setAutoCommit(true);
} catch (SQLException e) {
PrintWriter out = response.getWriter();
out.println("Error connecting to Oracle");
private void ReadFile (File Dir, String FileName, String
thedate, PrintWriter out) throws IOException {
try {
String cmd = "SELECT document FROM xmldocuments WHERE
docname = '"+FileName+"' and timestamp = to_date
('"+thedate+"', 'dd-mm-yyyy hh24:mi') for update";
out.println(cmd);
ResultSet rest = stmt.executeQuery(cmd);
rest.next();
CLOB clob = ((OracleResultSet)rest).getCLOB(1);
File theFile = new File(Dir+"\\"+FileName);
FileInputStream instream = new FileInputStream(theFile);
OutputStream outstream = clob.getAsciiOutputStream();
int size = clob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;
while ((length = instream.read(buffer)) != -1)
outstream.write(buffer, 0, length);
instream.close();
outstream.close();
} catch (SQLException e) {
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
out.println("Upload Servlet Test");
dir = new File("c:\\myprojects");
String fileName = null;
try {
MultipartParser mp = new MultipartParser(request,
10*1024*1024);
Part part;
while ((part = mp.readNextPart()) != null) {
String name = part.getName();
if (part.isFile()) {
// it's a file part
FilePart filePart = (FilePart) part;
fileName = filePart.getFileName();
if (fileName != null) {
// the part actually contained a file
long size = filePart.writeTo(dir);
out.println("file; name=" + name + "; filename=" +
fileName +
", filePath=" + filePart.getFilePath() +
", content type=" + filePart.getContentType() +
", size=" + size);
} else {
// the field did not contain a file
out.println("file; name=" + name + "; EMPTY");
out.flush();
} catch (IOException lEx) {
// this.getServletContext().log(lEx, "error reading or
saving file");
try {
OpenConnection(response);
stmt = cn.createStatement();
SimpleDateFormat formatter = new SimpleDateFormat ("dd-MM-
yyyy HH:mm");
java.util.Date TimeStamp = new java.util.Date();
String dateString = formatter.format(TimeStamp);
String cmd = "INSERT into XMLDOCUMENTS (DOCNAME,
TIMESTAMP, DOCUMENT) VALUES ('"+fileName+"', to_date
('"+dateString+"', 'DD-MM-YYYY HH24:MI'), EMPTY_CLOB())";
ResultSet rest = stmt.executeQuery(cmd);
ReadFile(dir, fileName, dateString, out);
} catch (SQLException e) {

The [url=http://otn.oracle.com/sample_code/tech/xml/xmlnews/
xnewshome.html]Dynamic News sample application shows how to read
and write CLOBs. The URL is:
http://otn.oracle.com/sample_code/tech/xml/xmlnews/xnewshome.html
Regards,
-rh

Similar Messages

  • Need help writing to file

    I have an ArrayList of XML strings. I am trying to write the XML strings in the arraylist to a text file. However, the only XML string that I see in the file is the first string repeated over and over. It is the only one getting to the file for some reason. I have tried the code below:
        public void writeToLogFile(String logFile, String msg) {
                try{   
                    FileWriter WriteFile = new FileWriter(logFile, true);  
                    BufferedWriter WriteBuff = new BufferedWriter(WriteFile); 
                    WriteBuff.write(msg+"\r\n");
                    WriteBuff.close(); 
                    WriteFile.close(); 
                }catch(IOException e) {
                    System.out.println("Error writing to file.");
    //        try {
    //            FileWriter fw = new FileWriter(logFile,true);
    //            PrintWriter pw = new PrintWriter(fw);
    //            pw.println(msg);
    //            pw.close();
    //        }catch(IOException ioExc) {
    //            System.out.println("error writing file");
        }  I tried the commented out code also. I've also tried using PrintStream. They all seem to give me the same result. My first thought was maybe I'm sending the same string to the method over and over but I'm not. If I loop through my arraylist of XML strings and do a System.out.println() instead of writing to file, I see that I am sending in different XML strings.
    Here's how I'm looping through the arraylist of XML strings call "al":
                for(int i=0; i<FileValues.length; i++) {
                    al = adapter.executeQuery(FileValues[0]);
    System.out.println("Writing to output file...");
    for(int x=0; x<=al.size()-1; x++) {
    //System.out.println(al.get(x).toString());
    test.writeToLogFile("c:/temp/a/limAdapterOutput", al.get(i).toString());
    System.out.println("Finished writing to output file.");
    What I'm doing is reading an arraylist (FileValues) of query parameters. For each parameter, I am querying a database based on the parameter and returning an arraylist of XML strings containing the query result. For each paramter, I'm returning about 1200 XML strings in the arraylist. Then I try to loop through the arraylist and write the XML strings to a file. However, this is when I run into my problem.
    Any ideas what's going on and how I can correct the problem? Thanks.

    for(int i=0; i<FileValues.length; i++) {
    al =
    al =
    al = adapter.executeQuery(FileValues[0]);
    System.out.println("Writing to output
    iting to output file...");
    for(int x=0; x<=al.size()-1; x++) {
    //System.out.println(al.get(x).toString());
    test.writeToLogFile("c:/temp/a/limAdapterOutput",
    ut", al.get(i).toString());
    System.out.println("Finished writing
    inished writing to output file.");
    When you write to the log file in the inner loop, it sounds like you want to use the x loop counter, not the i counter from the outer loop.  You comment out the print to System.out, which uses the x loop counter.  Why don't you do the same thing in the uncommented code?  Hard to follow exactly what you're doing, but maybe that will fix it.

  • Need help writing host program using LabView.

    Need help writing host program using LabView.
    Hello,
    I'm designing a HID device, and I want to write a host program using National Instrument's LabView. NI doesn't have any software support for USB, so I'm trying to write a few C dll files and link them to Call Library Functions. NI has some documentation on how to do this, but it's not exactly easy reading.
    I've written a few C console programs (running Win 2K) using the PC host software example for a HID device from John Hyde's book "USB by design", and they run ok. From Hyde's example program, I've written a few functions that use a few API functions each. This makes the main program more streamlined. The functions are; GetHIDPath, OpenHID, GetHIDInfo, Writ
    eHID, ReadHIC, and CloseHID. As I mentioned, my main program runs well with these functions.
    My strategy is to make dll files from these functions and load them into LabView Call Library Functions. However, I'm having a number of subtle problems in trying to do this. The big problem I'm having now are build errors when I try to build to a dll.
    I'm writing this post for a few reasons. First, I'm wondering if there are any LabView programmers who have already written USB HID host programs, and if they could give me some advice. Or, I would be grateful if a LabView or Visual C programmer could help me work out the programming problems that I'm having with my current program. If I get this LabView program working I would be happy to share it. I'm also wondering if there might already be any USB IHD LabView that I could download.
    Any help would be appreciated.
    Regards, George
    George Dorian
    Sutter Instruments
    51 Digital DR.
    Novato, CA 94949
    USA
    [email protected]
    m
    (415) 883-0128
    FAX (415) 883-0572

    George may not answer you.  He hasn't been online here for almost eight years.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • I need help writing a script that finds the first instance of a paragraph style and then changes it

    I need help writing a script that finds the first instance of a paragraph style and then changes it to another paragraph style.  I don't necessarily need someone to write the whole thing, by biggest problem is figuring how to find just the first instance of the paragraph style.  Any help would be greatly appreciated, thanks!

    Hi,
    Do you mean first instance of the paragraph style
    - in a chosen story;
    - on some chosen page in every text frames, looking from its top to the bottom;
    - in a entire document, looking from its beginning to the end, including hidden layers, master pages, footnotes etc...?
    If story...
    You could set app.findTextPreferences.appliedParagraphStyle to your "Style".
    Story.findText() gives an array of matches. 1st array's element is a 1st occurence.
    so:
    Story.findText()[0].appliedParagraphStyle = Style_1;
    //==> this will change a paraStyle of 1st occurence of story to "Style_1".
    If other cases...
    You would need to be more accurate.
    rgds

  • Need help writing small program!

    Hi. I'm learning Java programming, and I need help writing a small program. Please someone help me.
    Directions:
    Create a program called CerealCompare using an if-then-else structure that obtains the price and number of ounces in a box for two boxes of cereal. The program should then output which box costs less per ounce.

    class CerealCompare {
        public static void main(String[] args) {
            // your code goes here
    }Hope that helps.
    P.S. Java does not have an if-then-else statement.

  • Need Help Writing Server side to submit form via API

    Hey
    I need help writing a serverside application to submit
    information via API to a separate server.
    I have a client that uses constant contact for email
    campaigns. We want to add to her website a form taht submits the
    information needed to subscribe to her email list, to constant
    contact via API.
    FORM.asp :: (i got this one under control)
    name
    email
    and submits to serverside.asp
    SERVERSIDE.ASP
    In serverside.asp i need to have
    the API URL
    (https://api.constantcontact.com/0.1/API_AddSiteVisitor.jsp)
    username (of the constant contact account)
    password (of the constant contact account)
    name (submited from form.asp)
    email (submitted from form.asp)
    redirect URL (confirm.asp)
    Can anyone help get me going in the right direction?
    i have tried several things i found on the net and just cant
    get anyone to work correctly.
    One main issue i keep having is that if i get it to submit to
    the API url correctly - i get a success code, it doesnt redirect to
    the page i am trying to redirect to.
    ASP or ASP.NET code would be find.
    THANKS
    sam

    > This does require server side programming.
    > if you dont know what that is, then you dont know the
    answer to my question. I
    > know what i need to do - i just dont know HOW to do it.
    If you are submitting a form to a script on a remote server,
    and letting
    that script load content to the browser, YOU have no control
    over what it
    loads UNLESS there is some command you can send it that it
    will understand.
    No amount of ASP on your server is going to change what the
    remote script
    does.
    http://www.constantcontact.com/services/api/index.jsp
    they only allow their customers to see the instructions for
    the API so i
    can't search to see IF there is a redirect you can send with
    the form info.
    But posts on their support board say that there is.
    Alan
    Adobe Community Expert, dreamweaver
    http://www.adobe.com/communities/experts/

  • Need help with connecting file inputs to arrays

    In this assignment I have a program that will do the following: display a list of names inputed by the user in reverse order, display any names that begin with M or m, and display any names with 5 or more letters. This is all done with arrays.
    That was the fun part. The next part requires me to take the names from a Notepad file, them through the arrays and then output them to a second Notepad file.
    Here is the original program: (view in full screen so that the code doesn't get jumbled)
    import java.io.*;       //Imports the Java library
    class progB                    //Defines class
        public static void main (String[] arguments) throws IOException
            BufferedReader keyboard;                                  //<-
            InputStreamReader reader;                                 //  Allows the program to
            reader = new InputStreamReader (System.in);               //  read the the keyboard
            keyboard = new BufferedReader (reader);                  //<-
            String name;                 //Assigns the name variable which will be parsed into...
            int newnames;               //...the integer variable for the amount of names.
            int order = 0;              //The integer variable that will be used to set the array size
            String[] array;             //Dynamic array (empty)
            System.out.println (" How many names do you want to input?");   //This will get the number that will later define the array
            name = keyboard.readLine ();
            newnames = Integer.parseInt (name);                                         // Converts the String into the Integer variable
            array = new String [newnames];                                               //This defines the size of the array
            DataInput Imp = new DataInputStream (System.in);       //Allows data to be input into the array
            String temp;                                       
            int length;                                                                  //Defines the length of the array for a loop later on
                for (order = 0 ; order < newnames ; order++)                                //<-
                {                                                                           //  Takes the inputed names and
                    System.out.println (" Please input name ");                            //  gives them a number according to
                    temp = keyboard.readLine ();                                           //  the order they were inputed in
                    array [order] = temp;                                                  //<-
                for (order = newnames - 1 ; order >= 0 ; order--)                                //<-
                {                                                                                //  Outputs the names in the reverse 
                    System.out.print (" \n ");                                                   //  order that they were inputed
                    System.out.println (" Name " + order + " is " + array [order]);             //<-
                for (order = 0 ; order < newnames ; order++)                                  //<-
                    if (array [order].startsWith ("M") || array [order].startsWith ("m"))     //  Finds and outputs any and all
                    {                                                                         //  names that begin with M or m
                        System.out.print (" \n ");                                            //
                        System.out.println (array [order] + (" starts with M or m"));         //
                    }                                                                         //<-
                for (order = 0 ; order < newnames ; order++)                                            //<-
                    length = array [order].length ();                                                   //
                    if (length >= 5)                                                                    //  Finds and outputs names
                    {                                                                                  //  with 5 or more letters
                        System.out.print (" \n ");                                                      //
                        System.out.println ("Name " + array [order] + " have 5 or more letters ");      //<-
    }The notepad file contains the following names:
    jim
    laruie
    tim
    timothy
    manny
    joseph
    matty
    amanda
    I have tried various methods but the one thing that really gets me is the fact that i can't find a way to connect the names to the arrays. Opening the file with FileInputStream is easy enough but using the names and then outputing them is quite hard. (unless i'm thinking too hard and there really is a simple method)

    By "connect", do you just mean you want to put the names into an array?
    array[0] = "jim"
    array[1] = "laruie"
    and so on?
    That shouldn't be difficult at all, provided you know how to open a file for reading, and how to read a line of text from it. You can just read the line of text, put it in the array position you want, until the file is exhausted. Then open a file for writing, loop through the array, and write a line.
    What part of all that do you need help with?

  • I need help retrieving Microsoft files lost when upgrading to OSX Mavericks

    My daughter recently upgraded our Mac to the OSX Mavericks platform. Unfortunately, all of our Microsoft files, etc. are gone! I need to know how I can retrieve these files or if I can. I'm honestly not impressed with this new platform. I need help asap and your help is truly appreciated.

    You have to make the backup yourself. That's your only protection against file loss whether accidental or catastrophic. In fact you should have at least two of them - each done differently and on separate drives.
    If your files truly were "erased" then you can see if they can be recovered:
    General File Recovery
    If you stop using the drive it's possible to recover deleted files that have not been overwritten by using recovery software such as MAC Data Recovery, Data Rescue II, File Salvage or TechTool Pro.  Each of the preceding come on bootable CDs to enable usage without risk of writing more data to the hard drive.  Two free alternatives are Disk Drill and TestDisk.  Look for them and demos at MacUpdate or CNET Downloads. Recovery software usually provide trial versions that enable you to determine if the software would help before actually paying for it. Beyond this or if the drive has completely failed, then you would need to send the drive to a recovery service which is very expensive.
    The longer the hard drive remains in use and data are written to it, the greater the risk your deleted files will be overwritten.
    Also visit The XLab FAQs and read the FAQ on Data Recovery.
    Basic Backup
    For some people Time Machine will be more than adequate. Time Machine is part of OS X. There are two components:
    1. A Time Machine preferences panel as part of System Preferences;
    2. A Time Machine application located in the Applications folder. It is
         used to manage backups and to restore backups. Time Machine
         requires a backup drive that is at least twice the capacity of the
         drive being backed up.
    3. Time Machine requires a backup drive that is at least double the
         capacity of the drive(s) it backs up.
    Alternatively, get an external drive at least equal in size to the internal hard drive and make (and maintain) a bootable clone/backup. You can make a bootable clone using the Restore option of Disk Utility. You can also make and maintain clones with good backup software. My personal recommendations are (order is not significant):
      1. Carbon Copy Cloner
      2. Get Backup
      3. Deja Vu
      4. SuperDuper!
      5. Synk Pro
      6. Tri-Backup
    Visit The XLab FAQs and read the FAQ on backup and restore.  Also read How to Back Up and Restore Your Files. For help with using Time Machine visit Pondini's Time Machine FAQ for help with all things Time Machine.
    Although you can buy a complete external drive system, you can also put one together if you are so inclined.  It's relatively easy and only requires a Phillips head screwdriver (typically.)  You can purchase hard drives separately.  This gives you an opportunity to shop for the best prices on a hard drive of your choice.  Reliable brands include Seagate, Hitachi, Western Digital, Toshiba, and Fujitsu.  You can find reviews and benchmarks on many drives at Storage Review.
    Enclosures for FireWire and USB are readily available.  You can find only FireWire enclosures, only USB enclosures, and enclosures that feature multiple ports.  I would stress getting enclosures that use the Oxford chipsets especially for Firewire drives (911, 921, 922, for example.)  You can find enclosures at places such as;
      1. Cool Drives
      2. OWC
      3. WiebeTech
      4. Firewire Direct
      5. California Drives
      6. NewEgg
    All you need do is remove a case cover, mount the hard drive in the enclosure and connect the cables, then re-attach the case cover.  Usually the only tool required is a small or medium Phillips screwdriver.

  • Need Help-SOA 11g File Adapter unable to delete input file and its crashing

    Hi All
    Please find the details below:
    1. We have created a simple SOA composite to Read file from an input directory, archive the file in an archive directory using Inbound File Adapter Read
    and then use Outbound File Adapter Write to move the file to a output directory.
    2. File Adapter needs to delete the file after successful read/retrieval.
    3. We are using the "Use Trigger File" for invoking the file adapter. This is a new feature in SOA 11g
    4. Also we are using the option of reading the file as an attachment as we are not doing any transformation in the composite
    Issue Details_
    1. When the trigger file is put in the input directory for the first time, the File Adapter reads the file, archives it and moves it to the output directory
    2. However it does not delete the input file from the input directory and raises Fatal Exception mentioned below:
    [*2011-01-12T16:55:48.639+05:30] [soa_server1] [WARNING] [] [oracle.soa.adapter] [tid: weblogic.work.j2ee.J2EEWorkManager$WorkWithListener@19c243d]*
    [userId: <anonymous>] [ecid: 0000IptyLrL9_aY5TrL6ic1DBOS_000009,0] [APP: soa-infra] File Adapter FileAdapterTriggerFilePOC PostProcessor::
    Delete failed, the operation will be retried for max of [0] times
    [2011-01-12T16:55:48.639+05:30] [soa_server1] [WARNING] [] [oracle.soa.adapter] [tid: weblogic.work.j2ee.J2EEWorkManager$WorkWithListener@19c243d]
    [userId: <anonymous>] [ecid: 0000IptyLrL9_aY5TrL6ic1DBOS_000009,0] [APP: soa-infra] File Adapter FileAdapterTriggerFilePOC [[
    BINDING.JCA-11042
    File deletion failed.
    File deletion failed.
    File : C:\Dibya\AttachmentTest\InputDir\TestFile3.txt could not be deleted.
    Delete the file and restart server. Contact oracle support if error is not fixable.
    If any one has faced similar issues, kindly provide pointers on how to resolve it.
    Regards,
    Dibya

    Hi,
    Using the file adapter, you can poll from multilple locations...
    Keep the following property in your .jca file
    <property name="DirectorySeparator" value="," />
    While giving the path in File Adapter configuration, keep comma and give the next location....then the file will be picked up from the locations you gave....
    Hope this helps...
    Thanks,
    N

  • I need help with viewing files from the external hard drive on Mac

    I own a 2010 mac pro 13' and using OS X 10.9.2(current version). The issue that I am in need of help is with my external hard drive.
    I am a photographer so It's safe and convinent to store pictures in my external hard drive.
    I have 1TB external hard drive and I've been using for about a year and never dropped it or didn't do any thing to harm the hardware.
    Today as always I connected the ext-hard drive to my mac and click on the icon.
    All of my pictures and files are gone accept one folder that has program.
    So I pulled up the external hard drive's info it says the date is still there, but somehow i can not view them in the finder.
    I really need help how to fix this issue!

    you have a notebook, there is a different forum.
    redundancy for files AND backups, and even cloud services
    so a reboot with shift key and verify? Recovery mode
    but two or more drives.
    a backup, a new data drive, a drive for recovery using Data Rescue III
    A drive can fail and usually not if, only when
    and is it bus powered or not

  • Need help writing a query for following scenario

    Hi all, I need some help writing a query for the following case:
    One Table : My_Table
    Row Count: App 5000
    Columns of Interest: AA and BB
    Scenario: AA contains some names of which BB contains the corresponding ID. Some
    names are appearing more than once with different IDs. For example,
    AA BB
    Dummy 10
    Me 20
    Me 30
    Me 40
    You 70
    Me 50
    Output needed: I need to write a query that will display only all the repeating names with their corresponding IDs excluding all other records.
    I would appreciate any input. Thanks

    Is it possible to have a records with the same values for AA and BB? Are you interested in these rows or do you only care about rows with the same value of AA and different BB?
    With a slight modification of a previous posting you can only select those rows that have distinct values of BB for the same value of AA
    WITH t AS (
    SELECT 'me' aa, 10 bb FROM dual
    UNION ALL
    SELECT 'me' aa, 20 bb FROM dual
    UNION ALL
    SELECT 'you' aa, 30 bb FROM dual
    UNION ALL
    SELECT 'you' aa, 30 bb FROM dual
    SELECT DISTINCT aa, bb
      FROM (SELECT aa, bb, COUNT(DISTINCT bb) OVER(PARTITION BY aa) cnt FROM t)
    WHERE cnt > 1;

  • Need help replacing a file in AE

    Ok, here is my problem, I made a project on another computer and then I transfered to my computer. I dragged all of the images and sounds but ONE very important image. I downloaded that same image from online and I need help replacing the corrupted old image with the new one. Here is a picture with more detail.
    I tried copy & pasting the layer properties and effects, but that didn't work. Any ideas?
    Thanks,
    Emal

    For instructions on swapping out a footage item's source file, "Replace layer source with reference to another footage item".

  • Need Help with .nnlp File.............A.S.A.P.

    I'm having a problem also with my JNLP file. I have downloaded the program onto one computer and that computer is using j2re1.4.2_04
    The other computers I believe are all running j2re 1.4.2_05
    I'm not sure if that's make a difference, but on the computer with j2re 1.4.2_05 when going to the site where the .jnlp file is located, the application comes up and says Starting Application. After it gets to that screen it just stays there. I really need help with this as soon as possible.
    Here is my .jnlp file listed below:
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp
      spec="1.0+"
      codebase="http://www.appliedsolutions.com/placewiz"
      href="Placewiz.jnlp">
      <information>
        <title>Placement Wizard 4.0</title>
        <vendor>Applied Solutions, Inc.</vendor>
        <homepage href="index.html"/>
        <description>Placement Wizard 4.0</description>
        <description kind="short">Short description goes here.</description>
        <offline-allowed/>
      </information>
      <resources>
        <j2se version="1.4+"/>
        <j2se version="1.3+"/>
         <j2se version="1.5+"/>
        <jar href="Placewiz.jar"/>
      </resources>
      <security>
          <all-permissions/>
      </security>
      <application-desc main-class="com/asisoftware/placewiz/loader/Exec">
    </jnlp>

    This was due to a change in 1.4.2_05
    the main class attribute
    main-class="com/asisoftware/placewiz/loader/Exec">is wrong - it should be:
    main-class="com.asisoftware.placewiz.loader.Exec">this didnt seem to mater before 1.4.2_05, but some change in java since then caused this bad class specification to stop loading.
    /Andy

  • Need help with copying files onto external drive

    I need help! Trying to copy downloaded movie files from Vuze (which have downloaded successfully) and copy onto external hard drive to view them but it wont let me copy over to the external device. Any ideas how to fix this please???

    Can you explain the steps you used, and the error message (or symptom), that says the copy did not work? 

  • Need help to create file with name and current time stamp.

    I need to create .xlsx file exporting data from sql database and file name would be 'FileName' and current yyyymmdd. 
    I'm trying to use following code but it's keep saying  incorrect syntax near "+".
    EXEC p_CreateExcel 'sql64', 'NewFile', '\\hrfile1\Shared\Buying Report\NewFile'
    + CAST(YEAR(CURRENT_TIMESTAMP) AS VARCHAR)
    + RIGHT('00'+CAST(MONTH(CURRENT_TIMESTAMP) AS VARCHAR),2)
    + RIGHT('00'+CAST(DAY(CURRENT_TIMESTAMP) AS VARCHAR),2)+'.xlsx'

    This is what I have on EXEC p_CreateExcel
    USE [XePro01]
    GO
    /****** Object:  StoredProcedure [dbo].[p_CreateExcel]    Script Date: 02/26/2015 11:27:35 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER procedure [dbo].[p_CreateExcel]
            @db_name varchar(100),
            @table_name varchar(100), 
            @file_name varchar(100)
    as
    --Generate column names as a recordset
    declare @columns varchar(8000), @sql varchar(8000), @data_file varchar(100)
    select 
            @columns=coalesce(@columns+',','')+column_name+' as '+column_name 
    from 
            information_schema.columns
    where 
            table_name=@table_name
    select @columns=''''''+replace(replace(@columns,' as ',''''' as '),',',',''''')
    --Create a dummy file to have actual data
    select @data_file=substring(@file_name,1,len(@file_name)-charindex('\',reverse(@file_name)))+'\data_file.xls'
    --Generate column names in the passed EXCEL file
    set @sql='exec master..xp_cmdshell ''bcp "set fmtonly off select * from (select '+@columns+') as t" queryout "'+@file_name+'" -c -t, -T -S'''
    exec(@sql)
    --Generate data in the dummy file
    set @sql='exec master..xp_cmdshell ''bcp "set fmtonly off select * from XeProgst01.dbo.'+@table_name+'" queryout "'+@data_file+'" -c -t, -T -S'''
    exec(@sql)
    --Copy dummy file to passed EXCEL file
    set @sql= 'exec master..xp_cmdshell ''type '+@data_file+' >> '+@file_name+''''
    exec(@sql)
    --Delete dummy file 
    set @sql= 'exec master..xp_cmdshell ''del '+@data_file+''''
    exec(@sql)
    GO

Maybe you are looking for