简体   繁体   中英

Communication between jsp and java application

My project requirement is to develop a website which interacts with a mysql database and a java application which continuously runs on the server. user is on some remote computer he sends a request to the java application by executing a jsp code on the server, the jsp code waits for the application to send the information back. once the jsp recives the info. it sends a request to database. The is a special type of database built just because of limitations of a database and my project requirements. Please tell me how the request are sent ie what part of java will help me do this.

some link that have the same info but not exact Communication between two separate Java desktop applications .

EDIT: my question is.... what should i use in a jsp page such that i will be able to get info. from the application which stores data in a special form of datastructure. For now I dont want to talk to database. I just want to interact with a running application.

for example there is a program on the server which returns sum of two numbers which waits for someone to give it input. now my jsp sends two numbers to the application which adds the two numbers and gives back the sum to the jsp page. now jsp page code can do anything which is not my concern for now.

Database access through the Website is one of the essential components for any web-based development. JDBC, a mechanism that allows Java to talk to databases.

Java Database Connectivity (JDBC) is a standard Application Programming Interface (API) that is used to access databases, irrespective of the application driver and database product. In other words, JDBC presents a uniform interface to databases, however, if you change the database management system and your applications, you only need to change their driver. JDBC provides cross-DBMS connectivity to a wide range of SQL databases, and other tabular data sources, such as spreadsheets or flat files.

Here is the sample example:

import java.sql.*;
class DBQuery1{
    public static void main(String args[]) throws SQLException
  {
            try{
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               }catch(ClassNotFoundException e){};
        Connection cnn;
        Statement mystmt;
        ResultSet myrs;
            String op = "jdbc:odbc:JavaTest";
        cnn = DriverManager.getConnection(op,
                 "Admin", "");
        mystmt = cnn.createStatement();
            String sql;
            sql = "SELECT * FROM SupplierMaster " +
              "WHERE SupplierCode IN ( " +
                    "SELECT SCode " +
                    "FROM Relation " +
                    "WHERE PCode IN ( " +
                          "SELECT ProductCode " +
                          "FROM ProductMaster " +
                          "WHERE ProdCatg IN ( " +
                                "SELECT CatgID " +
                                "FROM CategoryMaster " +
                                            "WHERE CategoryName = 'Eatables')))";
        myrs = mystmt.executeQuery(sql);
            System.out.println("   "+"Sup Code" + "       " +"Sup Name" + "    " + "Sup Address    ");
            System.out.println("--------------------------------------------------------------------");
        String name, add;
            int code;
            while (myrs.next())
        {
             code = myrs.getInt("SupplierCode");
             name = myrs.getString("SupplierName");
             add = myrs.getString("SupplierAddress");
             System.out.println("       " + code +"       " + name+"        " + add);
        }
  }

}

More information you can find on this link:

http://webserver.ignou.ac.in/virtualcampus/adit/course/cst302/block2/cst302-bl2-u3.htm

Java applications most often communicate with a relational database through the use of a JDBC driver. The driver tells the application how to communicate with a specific database. Each database vendor often provides a driver for their particular database. In your case you will need the MySql Connecter/J driver , which you will include within your project as a jar file.

The JDBC drivers provided by database vendors implement an interface so connecting to different databases is pretty much the same except for a few syntax differences between parameters. There is a ton of information that can be found about how to connect to a database through a Java application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM