Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3309606
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:39:39+00:00 2026-05-17T21:39:39+00:00

I have created a JSP code where we can upload a .csv file. The

  • 0

I have created a JSP code where we can upload a .csv file. The JSP Code is supported by a java code that reads the .csv file and compares the urls in the file with the DB and adds it into to the DB if the urls are not already present.

The above scenario works absolutely fine when its executed in a windows system.

I uploaded the succesfully executed web application folder to a unix system. When I executed the program in the UNIX system, the tool is not comparing the URLs with the DB and adds it.

I suspect there should be some problem in reading the .csv file in a UNIX sytem.

Am using fedora(linux) OS. Kindly let me know whether there is any differences in reading .csv file between a windows system and a unix system.

The .csv file I am using has the following contents,

http://www.topix.com,sdfasdf
http://rss.news.yahoo.com/rss/topstories,Apple
http://www.apple.com/354,sdfasdf
http://www.topix.com/rss/city/emporia-ks,sdfasdf
http://www.topix.com/rss/,sdfasdf
http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=10/xml,sdfasdf
http://www.topix.com/rss/city/emp,sdfasdf
http://www.topix.com/rss/city/sandy-ut,dfgsdfg
http://www.apple.com,Yahoo

UPDATE FOR JEFF

try {
                    List items = uploadHandler.parseRequest(request);
                    Iterator itr = items.iterator();
                while(itr.hasNext()) {
                    FileItem item = (FileItem) itr.next();
                    if(item.isFormField()) {
                        out.println("File Name = "+item.getFieldName()+", Value = "+item.getString());
                    } else {
                        File file = new File(destinationDir,item.getName());
                        item.write(file);
                    //String temp=item.getName();
                        String fileToBeRead = "C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/Readcsv/files/"+item.getName();
                        String urlcnt="";
                        String srccnt="";
                        String contentType="";
                        Connection con=null;
                        Statement stmt=null;
                        final String rssvar="Rss";
                        final String other="Other";

                        int i=0;
                        int j=0;

                        try {
                            BufferedReader br = new BufferedReader(new FileReader(fileToBeRead));
                            String strLine = "";
                            StringTokenizer st = null;
                            while( (strLine = br.readLine()) != null)
                            {
                                st = new StringTokenizer(strLine, ",");
                                while(st.hasMoreTokens()){
                                    urlcnt=st.nextToken();
                                    srccnt=st.nextToken();
                                }
                                if(con==null){
                                    SQLConnection.setURL("jdbc:sqlserver://192.168.2.53\\SQL2005;user=sa;password=365media;DatabaseName=LN_ADWEEK");
                                        con=SQLConnection.getNewConnection();
                                        stmt=con.createStatement();
                                }
                                try{
                                    ResultSet rs;
                                    boolean hasRows=false;
                                    rs=stmt.executeQuery("select url from urls_linkins where url='"+urlcnt+"'");
                                while(rs.next()){
                                    hasRows=true;
                                    i++;
                                    }
                                if(!hasRows){
                                    j++;
                                    URL url = new URL(urlcnt);
                                    URLConnection url1=url.openConnection();
                                    contentType=url1.getContentType();
                                    PreparedStatement insertUrlStatement = con.prepareStatement("INSERT INTO urls_linkins(url, source_name, is_active, is_periodic, Link_Type, New_Entry) VALUES(?, ?, ?, ?, ?, ?)");
                                if(contentType.contains("rss") || contentType.contains("xml"))
                                {
                                    insertUrlStatement.setString(1, urlcnt);
                                    insertUrlStatement.setString(2, srccnt);
                                    insertUrlStatement.setInt(3, 1);
                                    insertUrlStatement.setInt(4, 0);
                                    insertUrlStatement.setString(5, rssvar);
                                    insertUrlStatement.setInt(6, 1);
                                    insertUrlStatement.executeUpdate();
                                    insertUrlStatement.close();
                                }
                                else{
                                    insertUrlStatement.setString(1, urlcnt);
                                    insertUrlStatement.setString(2, srccnt);
                                    insertUrlStatement.setInt(3, 1);
                                    insertUrlStatement.setInt(4, 0);
                                    insertUrlStatement.setString(5, other);
                                    insertUrlStatement.setInt(6, 1);
                                    insertUrlStatement.executeUpdate();
                                    insertUrlStatement.close();
                                    }
                                }
                                }
                                catch(Exception e){
                                    e.printStackTrace();
                                }
                            }

                            }catch(Exception e){
                                e.printStackTrace();
                            }finally{
                                out.println("<h2>"+j+" url has been added and "+i+" url already exists in the DB</h2>");
                                out.println("<a href=Addurl.jsp>Check URL</a>");
                                out.println("<a href=Addurl1.jsp>Add Single URL</a>");
                                out.println("<a href=uploadcsv.jsp>Add Multiple URL</a>");
                            }

                            }
                                out.close();
                            }
                            }catch(FileUploadException ex) {
                                log("Error encountered while parsing the request",ex);
                            } catch(Exception ex) {
                                log("Error encountered while uploading file",ex);
                        }

This is my reading code of the .csv file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:39:40+00:00Added an answer on May 17, 2026 at 9:39 pm

    Yes there will be differences in reading the .csv file when you transfer from a windows machine to a unix machine even when it’s a text file. There are hidden space characters which may be represented differently on the unix machine.

    I suspect that the reason it is not comparing the URLs is because the space characters might be different ASCII values so it thinks they are different and adds the URL into the DB.

    One suggestion would be to use the dos2unix command.

    http://kb.iu.edu/data/acux.html
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.