Köll & Sam Classroom Blog

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    [QUOTE=JosAH]
    Originally posted by Dököll

    The classpath mechanism is extremely easy actually: if you have a class
    foo.bar.YourCla ss (foo and bar are package names) then a .class file should
    exist somewhere in a directory X/foo/bar/YourClass.class . The X part should
    be an element in the classpath variable. Check your compiler flags for the
    option that stores the compiled files in their correct directory.

    kind regards,

    Jos
    Got it Jos, finnaly working... stupendous affair truly, I am so excited...

    Looks like the class vanished when copied over. Why would a class vanish in this fashion... I am sure there are logical reasons, will post as I find them.

    I also have a DHCP enabled connection to the internet, couldn't get pass my own network, doulble dose of reality there:-)

    I am attaching a new piece to this project, will see you in a bit.

    Thanks again, Jos!

    Dököll

    Comment

    • Dököll
      Recognized Expert Top Contributor
      • Nov 2006
      • 2379

      [QUOTE=Dököll]
      Originally posted by JosAH
      Got it Jos, finnaly working... stupendous affair truly, I am so excited...

      Looks like the class vanished when copied over. Why would a class vanish in this fashion... I am sure there are logical reasons, will post as I find them.

      I also have a DHCP enabled connection to the internet, couldn't get pass my own network, doulble dose of reality there:-)

      I am attaching a new piece to this project, will see you in a bit.

      Thanks again, Jos!

      Dököll
      OK, the boss smelt blood, he likes what my GUI does but does not want a standard GUI...

      I must now render a Servlet connection to database, grab data out of there email this data as a ticket.

      The servlet works fine, the connection to database is a miss though, been at it for 6 hours, almost. I suspect I need to find the right library for MetaData:

      import java.sql.SQLExc eption;
      import java.sql.Connec tion;


      I had similar problems when I forgot to add the above for the SQL portion. Just getting our normal "...is not a defined type..." for:

      [CODE=JAVA]
      (1) DatabaseMetaDat a dbMetaData = connection.getM etaData();

      and

      (2) ResultSetMetaDa ta resultsMetaData = resultSet.getMe taData();
      [/CODE]

      Can any of you tell me what if any the library MetaData relates to in Java.

      Will post portion of the code for looks, in a moment; got an idea...

      Thanks for your help!

      Dököll
      Last edited by Dököll; Jun 6 '08, 01:44 AM. Reason: text...[CODE=JAVA]

      Comment

      • Dököll
        Recognized Expert Top Contributor
        • Nov 2006
        • 2379

        Alright, it was nothing fancy, the idea did not work, I am also trying this using Tomcat 6... Servlet works with Tomcat also but still does not connect to database. At least there are no known issues with Servlets:

        [CODE=JAVA]
        protected void doGet(HttpServl etRequest request, HttpServletResp onse response)
        throws ServletExceptio n, IOException {
        response.setCon tentType("text/html");
        PrintWriter out = response.getWri ter();
        out.println("Lo oks like it is working");
        String driver = "com.microsoft. jdbc.sqlserver. SQLServerDriver ";
        String url = "jdbc:microsoft :sqlserver:Data Central";
        String username = "";
        String password = "";
        String tableName =
        request. getParameter ("tableName" );
        { if ((tableName == null) || (tableName.equa ls("")))
        tableName = "Library";
        }
        showTable(drive r,url,username, password, tableName, out);
        out.println("</CENTER></BODY></HTML>");
        }
        [/CODE]

        Here are the libraries thus far included:

        import java.awt.*;
        //import java.lang.annot ation.*;
        import java.awt.event. *;
        import java.sql.Driver Manager;
        import java.sql.Statem ent;
        import java.sql.Result Set;
        import java.sql.SQLExc eption;
        import java.sql.Connec tion;
        import java.io.IOExcep tion;
        import java.io.PrintWr iter;
        import javax.servlet.S ervletException ;
        import javax.servlet.h ttp.HttpServlet Request;
        import javax.servlet.h ttp.HttpServlet Response;
        import javax.swing.tex t.AttributeSet;
        import javax.swing.tex t.BadLocationEx ception;


        Have a look at the portion of the code with the problem:

        [CODE=JAVA]
        private void showTable(Strin g driver,
        String url,
        String username,
        String password,
        String tableName,
        PrintWriter out) {
        try {
        Class.forName(d river);
        Connection connection = DriverManager.g etConnection(ur l, username, password);
        DatabaseMetaDat a dbMetaData = connection.getM etaData();
        out.println("<U L>");
        String productName =
        dbMetaData.getD atabaseProductN ame();
        out.println(" <LI><B>Database :</B> " +
        productName);
        String productVersion =
        dbMetaData.getD atabaseProductV ersion();
        out.println(" <LI><B>Version: </B> " + productVersion );

        Statement statement = connection.crea teStatement();
        String query = "SELECT * FROM " + tableName;
        ResultSet resultSet = statement.execu teQuery(query);
        out.println("<T ABLE BORDER=1>");
        ResultSetMetaDa ta resultsMetaData = resultSet.getMe taData();
        int columnCount = resultsMetaData .getColumnCount ();
        out.println("<T R>");
        for(int i=1; i<columnCount+1 ; i++) {
        resultsMetaData .getColumnName( i);
        }
        out.println();
        while(resultSet .next()) {
        out.println("<T R>");
        for(int i=1; i<columnCount+1 ; i++) {
        out.print("<TD> " + resultSet.getSt ring(i));
        }
        out.println();
        }
        }

        [/CODE]

        This is not all of the code as you can tell tell, perhaps it'll give you an idea what library I must use; import java.lang.annot ation did not seem to work, I am still researching that:-)

        Again, thanks for your input, lines 10 and 24 or the portions I have issues with it seems.

        In a bit...

        Dököll
        Last edited by Dököll; Jun 6 '08, 05:03 AM. Reason: code...text

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          Two things I found after a quick skim through the code:

          - you don't need that annotation package.
          - that loop in lines 27 ... 29 doesn't do anything.

          What exactly is the problem? Does it compile? What does it do if it runs?

          kind regards,

          Jos

          Comment

          • Dököll
            Recognized Expert Top Contributor
            • Nov 2006
            • 2379

            Originally posted by JosAH
            Two things I found after a quick skim through the code:

            - you don't need that annotation package.
            - that loop in lines 27 ... 29 doesn't do anything.

            What exactly is the problem? Does it compile? What does it do if it runs?

            kind regards,

            Jos
            Greetings, Jos!

            Thanks for replying... Below was an attempt to increment columns each time the program reads database columns and found addtional columns next marker, loops until there are none, I am probably reading it wrong:-)

            [CODE=JAVA]

            for(int i=1; i<columnCount+1 ; i++) {
            resultsMetaData .getColumnName( i);
            }

            [/CODE]

            But to answer your question, the code runs fine and fires a .jsp file, but when I run program using the actual code above, MetaData seems to be an issue.

            I'll look at te loop again, and post the error.

            Hey, have a good Friday...

            In a bit!

            Dököll
            Last edited by Dököll; Jun 6 '08, 10:47 AM. Reason: text

            Comment

            • Dököll
              Recognized Expert Top Contributor
              • Nov 2006
              • 2379

              Originally posted by Dököll
              Greetings, Jos!

              Thanks for replying... Below was an attempt to increment columns each time the program reads database columns and found addtional columns next marker, loops until there are none, I am probably reading it wrong:-)

              [CODE=JAVA]

              for(int i=1; i<columnCount+1 ; i++) {
              resultsMetaData .getColumnName( i);
              }

              [/CODE]

              But to answer your question, the code runs fine and fires a .jsp file, but when I run program using the actual code above, MetaData seems to be an issue.

              I'll look at te loop again, and post the error.

              Hey, have a good Friday...

              In a bit!

              Dököll
              I'll just add it now Jos, will try the loop later and will yu know:
              [CODE=JAVA]
              at HelloWorld.show Table(HelloWorl d.java:64)
              at HelloWorld.doGe t(HelloWorld.ja va:48)
              at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:690)
              at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
              at org.apache.cata lina.core.Appli cationFilterCha in.internalDoFi lter(Applicatio nFilterChain.ja va:290)
              at org.apache.cata lina.core.Appli cationFilterCha in.doFilter(App licationFilterC hain.java:206)
              at org.apache.cata lina.core.Stand ardWrapperValve .invoke(Standar dWrapperValve.j ava:233)
              at org.apache.cata lina.core.Stand ardContextValve .invoke(Standar dContextValve.j ava:175)
              at org.apache.cata lina.core.Stand ardHostValve.in voke(StandardHo stValve.java:12 8)
              at org.apache.cata lina.valves.Err orReportValve.i nvoke(ErrorRepo rtValve.java:10 2)
              at org.apache.cata lina.core.Stand ardEngineValve. invoke(Standard EngineValve.jav a:109)
              at org.apache.cata lina.connector. CoyoteAdapter.s ervice(CoyoteAd apter.java:286)
              at org.apache.coyo te.http11.Http1 1Processor.proc ess(Http11Proce ssor.java:844)
              at org.apache.coyo te.http11.Http1 1Protocol$Http1 1ConnectionHand ler.process(Htt p11Protocol.jav a:583)
              at org.apache.tomc at.util.net.JIo Endpoint$Worker .run(JIoEndpoin t.java:447)
              at java.lang.Threa d.run(Unknown Source)

              [/CODE]

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                The getColumnName(i nt i) method simply returns the name of column i;
                your loop retrieves them all and simply ignores them. You could've taken that
                entire loop out of your program because all it does is consuming a bit of time.
                Read the API documentation for the ResultSetMetaDa ta class.

                kind regards,

                Jos

                Comment

                • Dököll
                  Recognized Expert Top Contributor
                  • Nov 2006
                  • 2379

                  Originally posted by JosAH
                  The getColumnName(i nt i) method simply returns the name of column i;
                  your loop retrieves them all and simply ignores them. You could've taken that
                  entire loop out of your program because all it does is consuming a bit of time.
                  Read the API documentation for the ResultSetMetaDa ta class.

                  kind regards,

                  Jos
                  Unbelievable, making more work for myself, thanks for pointing out API documentation for the ResultSetMetaDa ta class, keep you posted.

                  Köll

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    Originally posted by Dököll
                    Unbelievable, making more work for myself, thanks for pointing out API documentation for the ResultSetMetaDa ta class, keep you posted.

                    Köll
                    AAMOF *all* the classes you can use in Java SE are (heavily) documented. See
                    the Articles Index in the Java 'Howtos' section for a link from where you can
                    download the entire documentation; it's only a couple of mega bytes. Always
                    check the docs first for any class you want to use no matter whether or not you
                    think you already know that class; it pays back big times if you do so.

                    If you don't you might end up as lots of others who think the entire programming
                    world should be visual basic and be surprised again and again that Java doesn't
                    have a ClearScreen command or something else silly.

                    kind regards,

                    Jos

                    Comment

                    • Dököll
                      Recognized Expert Top Contributor
                      • Nov 2006
                      • 2379

                      Works like a charm, the API documenatation for both Database and ResultSet helped a great deal, the loop has since been reconsructed, I think I would have had issues beyond the API info:
                      [CODE=JAVA]

                      for (int i = 1; i <= colCount; ++i) {
                      out.println("<t h>" + resultSetMetaDa ta.getColumnNam e(i) + "</th>");
                      }
                      out.println("</tr>");
                      while (resultSet.next ()) {
                      out.println("<t r>");
                      for (int i = 1; i <= colCount; ++i)
                      out.println("<t d>" + resultSet.getSt ring(i) + "</td>");
                      out.println("</tr>");
                      }

                      [/CODE] Thanks a million for your help Jos...

                      We'll see you in a bit, I have a couple of question, I must fetch it from an email...

                      Comment

                      • Dököll
                        Recognized Expert Top Contributor
                        • Nov 2006
                        • 2379

                        Hello again!

                        In crystal reports, one can drag fields onto reports. Fields can be text,
                        date time, numbers, etc. I know they support html. I need to know if they
                        support all the html tags(eg: bgcolor, tables, etc).

                        Also, can you point me to a turtorial for calling Crystal reports from Java servlets
                        using simple java classes to provide data, I can't seem to find a sound document, an easy to understand one to follow, perhaps it cannot be done.

                        Would you know if integrating the Crystal reports viewer with an
                        application server like websphere/tomcat is doable?

                        Will keep searching meanwhile and will post my findings.

                        In a bit!

                        Dököll

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          Originally posted by Dököll
                          Works like a charm, the API documenatation for both Database and ResultSet helped a great deal, the loop has since been reconsructed, I think I would have had issues beyond the API info:
                          [CODE=JAVA]

                          for (int i = 1; i <= colCount; ++i) {
                          out.println("<t h>" + resultSetMetaDa ta.getColumnNam e(i) + "</th>");
                          }
                          out.println("</tr>");
                          while (resultSet.next ()) {
                          out.println("<t r>");
                          for (int i = 1; i <= colCount; ++i)
                          out.println("<t d>" + resultSet.getSt ring(i) + "</td>");
                          out.println("</tr>");
                          }

                          [/CODE] Thanks a million for your help Jos...
                          You're welcome of course; but what would you do if that ResultSet contains, say,
                          1,000,000 rows or so?

                          kind regards,

                          Jos

                          Comment

                          • JosAH
                            Recognized Expert MVP
                            • Mar 2007
                            • 11453

                            Originally posted by Dököll
                            Hello again!

                            In crystal reports, one can drag fields onto reports. Fields can be text,
                            date time, numbers, etc. I know they support html. I need to know if they
                            support all the html tags(eg: bgcolor, tables, etc).
                            If Crystal Reports is Java (and I think it is) the following from the API docs apply:

                            Originally posted by API documentation
                            The Swing JEditorPane text component supports different kinds of content via a plug-in mechanism called an EditorKit. Because HTML is a very popular format of content, some support is provided by default. The default support is provided by this class, which supports HTML version 3.2 (with some extensions), and is migrating toward version 4.0. The <applet> tag is not supported, but some support is provided for the <object> tag.

                            Originally posted by Dököll
                            Also, can you point me to a turtorial for calling Crystal reports from Java servlets
                            using simple java classes to provide data, I can't seem to find a sound document, an easy to understand one to follow, perhaps it cannot be done.

                            Would you know if integrating the Crystal reports viewer with an
                            application server like websphere/tomcat is doable?
                            I'd have to google for that but I don't assume you live in a googleless area :-)

                            kind regards,

                            Jos

                            Comment

                            • Dököll
                              Recognized Expert Top Contributor
                              • Nov 2006
                              • 2379

                              Originally posted by JosAH
                              If Crystal Reports is Java (and I think it is) the following from the API docs apply:






                              I'd have to google for that but I don't assume you live in a googleless area :-)

                              kind regards,

                              Jos
                              Oh no, Google's our friend, it's surely out there, thanks for your input... Just wondered if you had an idea, thanks for replying:-)

                              Getting an error though, I was coming over to bug you again:

                              Server Tomcat v6.0 Server at localhost failed to start.

                              Did I do something weird, it worked flawlessly before, well at least to some degree, if you remember the last post Jos... I must have done something to it, it's just not firing. Any ideas, googling it momentarily (does not seem to be coming up for me though)... probably beat you to it...hope some posted something:-)

                              Again thanks for your help...
                              Last edited by Dököll; Jun 9 '08, 02:52 AM. Reason: remark...

                              Comment

                              • Dököll
                                Recognized Expert Top Contributor
                                • Nov 2006
                                • 2379

                                Originally posted by Dököll
                                Oh no, Google's our friend, it's surely out there, thanks for your input... Just wondered if you had an idea, thanks for replying:-)

                                Getting an error though, I was coming over to bug you again:

                                Server Tomcat v6.0 Server at localhost failed to start.

                                Did I do something weird, it worked flawlessly before, well at least to some degree, if you remember the last post Jos... I must have done something to it, it's just not firing. Any ideas, googling it momentarily (does not seem to be coming up for me though)... probably beat you to it...hope some posted something:-)

                                Again thanks for your help...
                                I was fooling around with one of my xml files... all is well now...

                                This one's for the newbies, if you have this problem, look at your log file for Tomcat: C :\ Program Files\Apache Software Foundation...\. ..logs, it'll tell you where the problem is...

                                Later,

                                Dököll

                                Comment

                                Working...