开发者

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

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 ClassNotFou开发者_如何学运维ndException, 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 ?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜