Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

How to run this .java file in a web-app as a solo java application just to test it ?

0

46 views
package database;


    import java.io.IOException;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import database.Dbconnect;

    public class CreateQuery {
        Connection conn;

        /**
         * @throws ClassNotFoundException
         * @throws SQLException
         * @throws IOException
         */
        public CreateQuery() throws ClassNotFoundException, SQLException, IOException {
            conn=new Dbconnect().returnDatabaseConnection();
        }
        public int addNewLayertoDB(String feature_name,String shape,int Latitude , int Longitude , int feature_geom , String feature_details){
            try {
                PreparedStatement statement = null;
                String table_name = feature_name + "_" + shape; 
                String query = "CREATE TABLE EtherMap "+table_name+" ("+ feature_name+" (20))";
                statement = conn.prepareStatement(query);
                statement.setString(1, feature_name);
                statement.execute();
                String squery = "ALTER TABLE EtherMap" +table_name+"  ADD COLUMN geom int , ADD COLUMN shape character(10)";
                return 1;
            } catch (SQLException ex) {
                return 0;
            }
        }




        public void closeConn() throws SQLException {
            if (conn != null) {
                this.conn.close();
            }
        }

    }

I want to test this java code to see if anything is being updated in the postgresql database .

How do I do this in ecclipse IDE ?

asked March 16, 2011 1:29 pm CDT
posted via StackOverflow

2 Answers

3
 

There is nothing in this code that requires it to be in a web-app.

That's a good thing, as web-apps are components of their Servlet containers. In other words, you can't really run a standalone web-app, you must deploy it. Perhaps you'll deploy it in a micro-container that only contains your application, but there's nothing like true stand-alone running of a component.

In your case, just add a public static void main(String[] args) { to this code, put the desired calls to create the class and perform the operations, and give it a spin. If it's not just a "quick check" but a formal test that might be repeated, look into JUnit.

answered March 16, 2011 2:23 pm CDT
0
 

I would suggest writing a TestCase and making sure (assert)that the data you store in postgres, you can read it.

answered March 16, 2011 2:23 pm CDT

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions