Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1211

Re: How to post code correctly

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail
NNTP-Posting-Date Mon, 10 Oct 2011 06:09:55 -0500
Date Mon, 10 Oct 2011 04:09:49 -0700
From Patricia Shanahan <pats@acm.org>
User-Agent Mozilla/5.0 (Windows NT 5.2; WOW64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1
MIME-Version 1.0
Newsgroups comp.lang.java.help
Subject Re: How to post code correctly
References <4e92bb56$0$19700$9a566e8b@news.aliant.net>
In-Reply-To <4e92bb56$0$19700$9a566e8b@news.aliant.net>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Message-ID <oPOdnX2-bNQZTw_TnZ2dnUVZ_tWdnZ2d@earthlink.com> (permalink)
Lines 59
X-Usenet-Provider http://www.giganews.com
NNTP-Posting-Host 70.230.200.54
X-Trace sv3-NKCBhZXv6VimHGVjFQkzSAzlunovBUiJXiaDqIe1+uWm8f2tdENDi7Zr7kcu1HflhSJ6YwDLMGXDBzd!4mdNZp7XsO7NZXWfLO87OqTB9vf/aWI5dzHZhtfVns7FnMX6D3QA5dxKPEt7mKZJ//e3J5oKG6nA!jgwKL8nLZEbaEE15jdreHgXlmzbqnWHQRJtAP3VQ+X7nYA==
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 3323
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.help:1211

Show key headers only | View raw


On 10/10/2011 2:31 AM, Linus Flustillbe wrote:
> My previous posts to this group contained copy/paste Java code
> from the Eclipse IDE directly into slrn's message area.  80
> characters does not seem to be enough to contain well indented and
> formatted code.  I would like to do this correctly for future posts
> in an effort to be a good usenet citizen.  Does anyone have
> any suggestions?  I was thinking that if you did something like this
>
> package testing;
>
> import java.sql.*;
>
> public class ConnectionTest  {
>   public static void main(String[] args)
>    throws ClassNotFoundException, SQLException
> {
> Class.forName("oracle.jdbc.driver.OracleDriver");
> String tableName="LU_MEDIA_USAGE";
> TableConnect myConnection = new TableConnect();
> Statement stmt = myConnection.getStatement();
> ResultSet rset = myConnection.GetResultSet(stmt, tableName);
> while (rset.next()) {
> System.out.println (rset.getString(1));
> }
> stmt.close();
> }
> }
>      	
> It's not pretty but should now be SSCCE as long as all the classes are
> in the same package (no need to create a new package)

I usually use 2 spaces per indent level, and format, e.g. in Eclipse, to
well under 80 spaces. I rarely post code with more than 4 levels, so 2
spaces per indent only costs 6 columns, but makes it much more readable.

If I only need one public class I put all the code in one file, with no
package statement. That is not good practice for actual development, but
makes it simple for someone who wants to compile and run the code.

Your code would come out as:

import java.sql.*;

public class ConnectionTest {
   public static void main(String[] args)
       throws ClassNotFoundException, SQLException {
     Class.forName("oracle.jdbc.driver.OracleDriver");
     String tableName = "LU_MEDIA_USAGE";
     TableConnect myConnection = new TableConnect();
     Statement stmt = myConnection.getStatement();
     ResultSet rset = myConnection.GetResultSet(stmt, tableName);
     while (rset.next()) {
       System.out.println(rset.getString(1));
     }
     stmt.close();
   }
}

Patricia

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

How to post code correctly Linus Flustillbe <admin@nacs.dyndns-office.com> - 2011-10-10 09:31 +0000
  Re: How to post code correctly Patricia Shanahan <pats@acm.org> - 2011-10-10 04:09 -0700
    Re: How to post code correctly Lew <lewbloch@gmail.com> - 2011-10-10 08:47 -0700
      Re: How to post code correctly Patricia Shanahan <pats@acm.org> - 2011-10-10 09:19 -0700
      Re: How to post code correctly Linus Flustillbe <admin@nacs.dyndns-office.com> - 2011-10-10 19:27 +0000
  Re: How to post code correctly Roedy Green <see_website@mindprod.com.invalid> - 2011-10-10 05:55 -0700
    Re: How to post code correctly Linus Flustillbe <admin@nacs.dyndns-office.com> - 2011-10-10 13:18 +0000
      Re: How to post code correctly markspace <-@.> - 2011-10-10 07:25 -0700
      Re: How to post code correctly Roedy Green <see_website@mindprod.com.invalid> - 2011-10-10 14:56 -0700
        Re: How to post code correctly Linus Flustillbe <admin@nacs.dyndns-office.com> - 2011-10-10 23:57 +0000
    Re: How to post code correctly Patricia Shanahan <pats@acm.org> - 2011-10-10 09:23 -0700
      Re: How to post code correctly Linus Flustillbe <admin@nacs.dyndns-office.com> - 2011-10-10 19:24 +0000
      Re: How to post code correctly Roedy Green <see_website@mindprod.com.invalid> - 2011-10-10 15:03 -0700
  Re: How to post code correctly Lew <lewbloch@gmail.com> - 2011-10-10 18:56 -0700
  Re: How to post code correctly Gorman <gormenski@gmail.com> - 2011-10-11 19:45 -0700

csiph-web