Stefano Mtangoo 455 Senior Poster

Haven't anyone come across this error?

debug:
Have no FileObject for C:\Program Files\Java\jdk1.6.0\jre\lib\sunrsasign.jar
Have no FileObject for C:\Program Files\Java\jdk1.6.0\jre\classes
Table Rows
java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:795)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:839)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5657)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5577)
at dbclass.MainApp.main(MainApp.java:16)
BUILD SUCCESSFUL (total time: 3 seconds)

Stefano Mtangoo 455 Senior Poster

How do you do it?
Check this

Stefano Mtangoo 455 Senior Poster

I wonder why this does not insert data :-O

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "java.sql.*" %>
<%--@page import = "dbfiles.*" --%>


<%
            //VDbManager mgr = new VDbManager();
            String sqlApp = "INSERT INTO application VALUES (NULL, 810, 2010-08-26, 2010-10-27, 30, \"Dummy Leave\",  \"Dummy Reason \",  \"Applied \")";
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/lam", "root", "ilovejesus");
            Statement st = connection.createStatement();

            int i = 1000;

            out.println("Entering the loop...");
            while (i > 0) {
                /*mgr.dbChange(sqlApp);
                mgr.dbChange(sqlApproval);
                mgr.dbChange(sqlUser);
                 */
                try {
                    st.executeUpdate(sqlApp);
                    st.executeUpdate(sqlApproval);
                    st.executeUpdate(sqlUser);
                    out.println(i + "<br />");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                i--;
            }
            out.println("Done!");
            connection.close();
%>
Stefano Mtangoo 455 Senior Poster

Any help

Stefano Mtangoo 455 Senior Poster

Now I have re-written the code and I get error:

debug:
Have no FileObject for C:\Program Files\Java\jdk1.6.0\jre\lib\sunrsasign.jar
Have no FileObject for C:\Program Files\Java\jdk1.6.0\jre\classes
Table Rows
java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:795)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:839)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5657)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5577)
at dbclass.MainApp.main(MainApp.java:16)
BUILD SUCCESSFUL (total time: 3 seconds)

Here is the code, I wonder what went wrong

//DBClass.java
package dbclass;
//imports
import java.sql.*;

class DBClass {
    //private

    private String dbHost = "jdbc:mysql://localhost:3306/";
    private String dbUser = "root";
    private String dbPassword = "ilovejesus";
    private String dbClass = "com.mysql.jdbc.Driver";
    private String dbName = "sitedb";

    public Connection conn = null; //holds connection
    public ResultSet rs = null; //holds result

    //informartive query
    public ResultSet dbSelect(String sql) throws SQLException {
        try {
            Class.forName(this.dbClass).newInstance();
            conn = DriverManager.getConnection(this.dbHost+this.dbName, this.dbUser, this.dbPassword);
            Statement stmt = this.conn.createStatement();
            rs = stmt.executeQuery(sql);
        } catch (Exception e) {
            //should email admin the error message
            e.printStackTrace();
            rs = null;
        }
        finally{
            this.conn.close();
            return rs;
        }        
    }

    //All update methods
     public int dbChange(String sql) throws SQLException {
         int i=24;
        try {
            Class.forName(this.dbClass).newInstance();
            conn = DriverManager.getConnection(this.dbHost+this.dbName, this.dbUser, this.dbPassword);
            PreparedStatement preparedSQL = this.conn.prepareStatement(sql);
            i = preparedSQL.executeUpdate();

        } catch (Exception e) {
            //should email admin the error message
            e.printStackTrace();
            i= -24; //error somewhere
        }
        finally{
            this.conn.close();
            return i; //error somewhere
        }
    }


    
}//end class
//MainApp.java
package dbclass;

import java.sql.*;

public class MainApp {

    public static void main(String[] args) {
        String query = "Select * …
Stefano Mtangoo 455 Senior Poster

Now I have re-written the code and I get error:

debug:
Have no FileObject for C:\Program Files\Java\jdk1.6.0\jre\lib\sunrsasign.jar
Have no FileObject for C:\Program Files\Java\jdk1.6.0\jre\classes
Table Rows
java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:795)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:839)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5657)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5577)
at dbclass.MainApp.main(MainApp.java:16)
BUILD SUCCESSFUL (total time: 3 seconds)

Here is the code, I wonder what went wrong

//DBClass.java
package dbclass;
//imports
import java.sql.*;

class DBClass {
    //private

    private String dbHost = "jdbc:mysql://localhost:3306/";
    private String dbUser = "root";
    private String dbPassword = "ilovejesus";
    private String dbClass = "com.mysql.jdbc.Driver";
    private String dbName = "sitedb";

    public Connection conn = null; //holds connection
    public ResultSet rs = null; //holds result

    //informartive query
    public ResultSet dbSelect(String sql) throws SQLException {
        try {
            Class.forName(this.dbClass).newInstance();
            conn = DriverManager.getConnection(this.dbHost+this.dbName, this.dbUser, this.dbPassword);
            Statement stmt = this.conn.createStatement();
            rs = stmt.executeQuery(sql);
        } catch (Exception e) {
            //should email admin the error message
            e.printStackTrace();
            rs = null;
        }
        finally{
            this.conn.close();
            return rs;
        }        
    }

    //All update methods
     public int dbChange(String sql) throws SQLException {
         int i=24;
        try {
            Class.forName(this.dbClass).newInstance();
            conn = DriverManager.getConnection(this.dbHost+this.dbName, this.dbUser, this.dbPassword);
            PreparedStatement preparedSQL = this.conn.prepareStatement(sql);
            i = preparedSQL.executeUpdate();

        } catch (Exception e) {
            //should email admin the error message
            e.printStackTrace();
            i= -24; //error somewhere
        }
        finally{
            this.conn.close();
            return i; //error somewhere
        }
    }


    
}//end class
//MainApp.java
package dbclass;

import java.sql.*;

public class MainApp {

    public static void main(String[] args) {
        String query = "Select * …
Stefano Mtangoo 455 Senior Poster

Since I'm learning, I googled a little and rewrote my code. I want at the end to write a generic class I will use for all my application to connect to database. For now, All I want is to test make sure that things are working. Here is my test class

MainApp.java

package dbclass;

/**
 *Testing JDBC
 */
public class MainApp {
    public static void main(String[] args){
        String query = "Select * FROM logintable";
        DBClass db = new DBClass();
        db.getDbInfo(query);
    }

}

DBClass.java

package dbclass;
//imports
import java.sql.*;

class DBClass {
    //private

    private String dbHost = "jdbc:mysql://localhost:3306";
    private String dbUser = "root";
    private String dbPassword = "ilovejesus";
    private String dbClass = "com.mysql.jdbc.Driver";

    public void getDbInfo(String sql) {
        try {
            Class.forName(this.dbClass).newInstance();
            Connection con = DriverManager.getConnection(this.dbHost, this.dbUser, this.dbPassword);
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            String dbtime;
            while (rs.next()) {
                dbtime = rs.getString(1);
                System.out.println(dbtime);
            } 
        }
        catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }

    }
}  //end class
Stefano Mtangoo 455 Senior Poster

Hi,
I'm beginning JDBC and I'm conversant in SQL. But I need to Connect to database and that where the problem lies. All I have done is adding mysql/j connector Jar to Netbeans project and wrote code below to test. It cannot connect to database. Also IDE throws error:

package dbclass;
//imports
import java.sql.*;

public class DBClass {

    public ResultSet changeDBInfo() throws SQLException {
        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(this.host, this.userName, this.passWord);
            if (!conn.isClosed()) {
                System.out.println("Connected Successfully");
            }
            Statement st = conn.createStatement();
            return st;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            conn.close();
        }
        return null;
    }
    //credentials
    private String host = "jdbc:mysql://localhost:3306/mysql";
    private String userName = "root";
    private String passWord = "ilovejesus";
}
Stefano Mtangoo 455 Senior Poster

You forgot to add ActionListerner?
It connects GUI code to actual actions :)

Stefano Mtangoo 455 Senior Poster

Thanks mschroeder,
Anyone with such helpful tips is welcomed :)

Stefano Mtangoo 455 Senior Poster

Duh!
I will check it

Stefano Mtangoo 455 Senior Poster

Hi,
How do these relate and differ?
I see them Used with queries but cannot understand. I'm just starting JDBC. Sorry if it is noobish ;)

Stefano Mtangoo 455 Senior Poster

here is beautiful examples:

Stefano Mtangoo 455 Senior Poster

Nothing special. It is just Javascript library that simplifies things. And yes it can play with PHP very well. What specifically you want to do? You might find it already full implemented there
see this example though a little complex

Stefano Mtangoo 455 Senior Poster

Oops! Sorry 'bout that...

Its no big deal buddy ;)

Stefano Mtangoo 455 Senior Poster

I'm new to JSp but wouldn't tag begin with <% instead of <c:?

<% 
  if(sessionScope.qCounter == 0){
  <!--............do your stuff.....-->
}
else{
  <!--.................do your stuff .........-->
}
  %>
Stefano Mtangoo 455 Senior Poster

I JUST CHECKED THE LINE 29,AND PUT SOMETHING LIKE THIS <?PHP.

Well you forgot to write PHP start tag.
Next time you post question, put the error message as well

Stefano Mtangoo 455 Senior Poster
HttpSession session = request.getSession();
if(session==null){
	RequestDispatcher rd = context.getRequestDispatcher("/demo/inner.jsp");
	rd.forward(request,response);
}

Cooked from different google links and untested. Try it and see.
I'm not JSP maverick either

Stefano Mtangoo 455 Senior Poster

Are you aware that PHP also has a DOM class?
check it out here:
http://us3.php.net/manual/en/book.dom.php

Kidding? That is for XML parsing J! :)
I thought PHP wanted JS out of business but then how could Server side things be done on Client.

@leegeorg07 ,
I would suggest you learn JQuery. It is really simple to do Some JS fun

Stefano Mtangoo 455 Senior Poster

Good explanations from this post

PHP cannot easily control the client's browser, except indirectly by generating Javascript which does.

The "problem" is that PHP's work is finished once it generates the page to be sent to the browser. PHP is run on the server,

Javascript, as it is normally encountered, is client-side technology, that is, it runs on the client's browser, not on the web server. (There is server-side javascript, but it only works with Netscape's server, IIRC).

You *could* work out a system where the PHP script establishes a TCP connection to the client's computer and sends a file to the client's own printer (e.g. using a combination of popen() and ssh), but

(a) there are going to be major security issues here,
and
(b) you need tight control over *both ends* of the connection (client and server); you will simply not find a solution that will work on most client's machines.

May this be informative,

Stefano Mtangoo 455 Senior Poster

I'm zero in MFC but I would suggest wxWidgets. Many big app are made of it and it si cross platform and... MFC-ish (according to Coders)

Stefano Mtangoo 455 Senior Poster

where have you reached so far?

Stefano Mtangoo 455 Senior Poster

Here is beautifully simplified solution but it is "either or". I mean either you persevere and resolve your problem or you are out :)
Here it goes:
learn quickly PHP via this link
Learn MySQL via this one
Come back and use this information to solve your problem
If you hit a wall here is the right place to go

Stefano Mtangoo 455 Senior Poster

I have recently being interested in Web security and I have some reading. I then found this post, and it is great. I would like to hear what do you think is missing or what isn't necessary a.k.a overkill.
It is not criticizing as such but discussing security ;)

Stefano Mtangoo 455 Senior Poster

In My laptop default is IJ and in my office I use Netbeans 6.8.
They are both good

Stefano Mtangoo 455 Senior Poster

+1 for IntelliJ or Netbeans. Eclipse is also good

Stefano Mtangoo 455 Senior Poster

You should said that blog is about how-to setup some of above mentioned tools/applications instead of explanation why ;)

Where did my another post go :-O
Before I posted that link I had asked about how to setup SVN server to play with Tomcat. May be I forgot to click submit? That blog answered that Question and few other like you said.

That post, amazing is not there :-O

Stefano Mtangoo 455 Senior Poster

For anyone wondering how, this blog answered it simply. I will let this thread on for a while

Stefano Mtangoo 455 Senior Poster

Glad I helped :)

Stefano Mtangoo 455 Senior Poster

Thanks,
Let me start implementing what you have said, then I will be back
Thanks a lot

Stefano Mtangoo 455 Senior Poster

Thanks a lot. Three questions on that:
1. Is there tutorial for that?
2. Example website done fully using the technique?
3. Can I create different templates without re-coding the php part (I guess yes?)

Stefano Mtangoo 455 Senior Poster

Your friends should already know about

  • Maven 2 or Ant for various tasks (fetch repositories, run procedures like compile, test, execute or package - often included in IDE)
  • revision control system - Subversion or GitHub
  • issue tracker - Bugzilla, Jira (commercial product), Trac
  • wiki - like these
  • blog - to tell others about your project and progress of it

I'm sure other guys can add some other products, but you can consider this basic setup

Ok, I'm new to Java in terms of Tools so would you please explain little on Maven/Ant? What do you prefer? For other Bugs tracker, Wiki, etc I'm comfortable with learning them.

Use a version control system. Having your code placed at a central repository which would then be used by collaborating developers is probably the best way to track of changes made to files and share code in a clean way without mailing each other 'zip' files. That being said, how you implement this in your project depends on a couple of things. Do you have problems with your code being publicly exposed/published?

If not, then head over to Google code which is basically a free project hosting solution provided by Google. You can to choose between two version control systems (VCS); SVN which is a centralized VCS and Mercurial which is a distributed VCS. Though the concept and adoption of the latter is gaining pace among the developer community I'd still recommend …

Stefano Mtangoo 455 Senior Poster

Rain TPL much easier once you know the basics of templating. Perhaps Smarty is the 'industry standard' and has better documentation. I would imagine that starting with the basic functions of Smarty will get you going.
The demo pages are a good starter, although unless you've got a little understanding of OOP, it can look daunting.
Haven't used a templater for a while. Still using includes. I find them far more flexible. Okay, the echoing of php variables is a pain with the full syntax every time, but I'm not too bothered about that.

Thanks Ardav. I will try to jump into smarty

Has anyone else ever taken the XML/XSL approach?

I found generating XML representations of my output and using XSL style sheets to do the transformations with the php XSL extension to quite powerful and surprisingly fast.

It also truly separates your php from your template while also being a w3 standard.

Haven't even tried that. Any demo/Short tutorial for quick look?

I use smarty. For me it makes it easy to share, since most people I share code with also use smarty. I have to say that the docs are a definite plus. XML/XSLT comes in handy once in a while, so I use a smarty plugin to handle those situations.

Here is another encouragement to use smarty!

Stefano Mtangoo 455 Senior Poster

Cool, I will assume you are copying files from local direction so no TCP/HTTP. Then here are some links that does the same thing:
http://www.rgagnon.com/javadetails/java-0064.html
http://www.java2s.com/Code/Java/File-Input-Output/CopyfilesusingJavaIOAPI.htm
http://www.roseindia.net/java/beginners/CopyFile.shtml

Haven't done that but If I was to do the same, I will use copyTo Method. See tutorial here how to use it.

Stefano Mtangoo 455 Senior Poster

Are you copying from local file or downloading from net?
Your code for that part?

Stefano Mtangoo 455 Senior Poster

Hi all,
I know many here have been working on big project and can help me on this. We will be having a project to do and we are more than 3 people. We will be working at different times and places(We are not employed developers per se Just hobbyists). My friends are Java addicts and hence we will be doing it in Java as web app. I have two questions that i need your help:
1. What is the best way to manage such project so that we won't collide?

2. What are advice(s) you will like to give someone like me working with team for first time? (All the time I have been working on personal projects alone)

Stefano Mtangoo 455 Senior Poster

see here

Ancient Dragon commented: nice link :) +28
Stefano Mtangoo 455 Senior Poster

I prefer to make my own so that way it is guaranteed to be secure and with all the features I need. And the process of making the template is fun too. But if I ever need to scratch out a quick cms then I would use mediawiki with custom extensions.

Do you code simple includes or just full fledged ones?

I've started to use Rain TPL. Used to use Smarty.

Rain seems more lightweight and user friendly. However the documentation isn't as good. But, once you've used one templating system, I suppose the basics are pretty much the same in each.

I also use my own, which is just a collection of common includes, so not a proper grown-up templating system, but that's they way I like to work most of the time.

Do you still use Rain TPL? How is it doing? I'm still hesitating jump into smarty wagon ;)

Stefano Mtangoo 455 Senior Poster

Very possible!
when user clicks generate button, you collect the checkboxed things and calculate whatever you calculate and dynamically creating a table as pointed in last image

Stefano Mtangoo 455 Senior Poster

and both members.php and login.php should be in one place for above code to work without modification. Use code tags to make your code readable

Stefano Mtangoo 455 Senior Poster

want to tes if user is logged in right?
if yes then at very top of page add these line (before anything else)

session_start();
if($_SESSION['logged'] ){
    echo "You are logged in";
}
else{
//redirect to login page
header("Location:login.php");
}

and on your above code remember to remove exit after

$_SESSION['logged'] = true;

and add this

header("Location:members.php");

to redirect to members area.

Confused, just cry out and someone will answer ;)

Stefano Mtangoo 455 Senior Poster

Fundamentally same:

  • servlet will use doGet() or doPost() (other methods are not used often)
  • create session
  • attach it to next forward/redirect servlet does

Thanks Peter,
I'm trying to familialize with JSP as I have to do something with my colleagues which are Java addicts ;)

Stefano Mtangoo 455 Senior Poster

I will update it. Do you have anything you will want to add? I have an assignment to do this week may be next week I will beautify it and PDFing it :)

Stefano Mtangoo 455 Senior Poster

>Where to read a concise tutorial

Readme.

Thanks I will have to check again

>What is difference between JSP login and PHP

Not a real question. (http://en.wikipedia.org/wiki/Login)

It is friend. In PHP I have to submit a form and catch it via $_POST superglobal. I will then have to start session and so thing goes on and on. I was asking how does this differ in JSP? Are things the same or dramatic different?

Thanks

Stefano Mtangoo 455 Senior Poster

I have done a lot of PHP but never JSP. I have checked tutorial but not gone too far. I see there are Java beans and some servlets which I'm zero brain at. So I have two questions:
1. Where to read a concise tutorial (Not too detailed I mean) on those prerequisites to grasp the tutorial (Having some Java/Swing background)?

2. What is difference between JSP login and PHP(HTM forms/$_POST, session, etc)?

Stefano Mtangoo 455 Senior Poster

I have several books on C++ but couldn't find a think which explains the above to me.

Cheers
Danny2000

I would defer to use Books and get jumpstart with short concise tutorials until I get brush up. Then I will go back to the book and get comprehensive tutorial

Stefano Mtangoo 455 Senior Poster

If/Else will evaluate only bools.
Switch will evaluate integers in whatever form they come from.
Jonsca have given solid examples. BTW have you passed this tutorial and this one?

Stefano Mtangoo 455 Senior Poster

What exactly do you want to do? Once we know the answer then we'll be able to suggest/help

Stefano Mtangoo 455 Senior Poster

I was looking for Jump start tutorial for JSP/MySQL. I found Peter budo's sticky. Since I wanted to learn it even offline I decded to put it in word Doc.

I will nice format it if I get time and make PDF out of it. However I know some might have that time or might be more skilled than I do. So I post here with very little editing (And formatting of course).

I have to rush somewhere, so if you have time, take it add something and repost back. Peter, please check if there is anything to add or remove, even my bragging ;)

Thanks

Stefano Mtangoo 455 Senior Poster

Your post is "simple...."
Make that simple one work and make it complex slowly