HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Web Database Publishing"
Vol. 2, Issue 7, p. 18

	

Listing 1.
 
package kiosk; 

import java.awt.*; 
import java.net.*; 
import java.applet.*; 
import java.util.Properties; 
/* if you are using JDK 1.02, import xjava.sql.* 
 * if you are using JDK 1.1 import java.sql.* 
 */ 
import xjava.sql.*; 
import weblogic.common.*; 

/* inquiry.java 
 inquiry service for Fantastic Reading book kiosk 
 using Weblogic native JDBC driver 
 */ 

public class inquiry extends Applet { 

  T3Client t3 = null; 
  Connection conn = null; 

  TextArea ta; 
  Label lb; 
  TextField searchfield; 
  Button submit_button; 

  public void init() { 

    Panel p1; 

    setLayout(new BorderLayout()); 

    lb = new Label("Title to be searched : "); 
    searchfield = new TextField(30); 

    ta = new TextArea(12, 50); 

    submit_button = new Button("Go"); 

    p1 = new Panel(); 
    p1.add(lb); 
    p1.add(searchfield); 
    p1.add(submit_button); 
  

    add("North", p1); 
    add("South", ta); 

  } 
  

  public boolean action(Event e, Object obj) {  

    String search_string, result_string; 

    if (e.target == submit_button) 
    { 
      search_string = searchfield.getText(); 
      ta.setText(""); 

      if (search_string.length() == 0) 
      { 
        ta.setText("Pls enter a search string!"); 
        ta.show(); 
        return true; 
      } 

      result_string = search_title(search_string); 
      if (result_string != null) { 
         ta.appendText(result_string); 
         return true; 
      } else { 
         return false; 
      } 
    } 

    return false; 
   
  } 

  public void stop() { 
    try {conn.close();}    catch (Exception e) {;} 
    try {t3.disconnect();} catch (Exception e) {;} 
  } 

  void establish() { 

    try { 

      t3 =  new 
        T3Client("t3://cobam.ccs.np.ac.sg:7001"); 
      t3.connect(); 
       
      Properties dbproperties = new Properties(); 
      dbproperties.put("user", "sa"); 
      dbproperties.put("password", ""); 
      dbproperties.put("server", "cobam"); 
    
       
      Properties t3properties = new Properties(); 
      t3properties.put("weblogic.t3", t3); 
      t3properties.put("weblogic.t3.dbprops", 
         dbproperties); 
      t3properties.put("weblogic.t3.driverClassName", 
         "weblogic.jdbc.dblib.Driver"); 
      t3properties.put("weblogic.t3.driverURL", 
         "jdbc:weblogic:mssqlserver"); 
       
      Class.forName("weblogic.jdbc.t3client.Driver"); 
      conn = 
      DriverManager.getConnection("jdbc:weblogic:t3client", 
         t3properties); 
       

    } catch (Exception e) { 
      e.printStackTrace(); 
    } 

 } 
       

 String search_title(String title_string) { 

    String str; 
    StringBuffer sb1 = new StringBuffer(); 
    int counter; 

    if ((t3 == null) || (conn == null)) { 
       establish(); 
    } 

    if ((t3 != null) && (conn != null)) { 
       str = new 
        String("select * from book where title like '%"+ 
             title_string+"%'"); 
         
        try { 
          Statement stmt = conn.createStatement(); 

          stmt.execute(str); 
          ResultSet rs = stmt.getResultSet(); 
          counter = 0; 

          while(rs.next()) { 
             counter++; 
             sb1.append(counter+ 
               ") Catalogue No. :  "+ 
               rs.getString("catalogue_no")+ 
               "\n"+ 
               "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"+ 
               "Title     :"+ 
               rs.getString("title")+ 
               "\n"+ 
               "Author    :"+ 
               rs.getString("major_author")+ 
               "\n"+ 
               "Publisher :"+ 
               rs.getString("publisher")+ 
               "\n"+ 
               "Unit Price:"+ 
               rs.getString("unit_price")+ 
               "\n\n"); 
             
           } 

           if (counter == 0) { 
              return("No matching title !"); 
           } else { 
              return(sb1.toString()); 
           } 

        } catch(Exception exception) { 
          return("SQL query Error"); 
        } 

    } else { 
      return(null); 
    } 

  } 

} 

Listing 2.
 
<html> 
<head> 
<title>Fantastic Reading Book Store</title> 
</head> 

<body> 
<img src=logo.gif> 
<APPLET CODEBASE="http://cobam.ccs.np.ac.sg/" 
CODE="kiosk.inquiry.class" 
width=500 height=240> 
</APPLET> 
</body> 
</html> 

Listing 3.
 
package kiosk; 

import java.awt.*; 
import java.net.*; 
import java.applet.*; 
import java.util.Properties; 
/* if you are using JDK 1.02 import xjava.sql.* 
   if you are using JDK 1.1 import java.sql.* 
 */ 
import xjava.sql.*; 
import weblogic.common.*; 

/* inquiry.java 
 inquiry service for Fantastic Reading book kiosk 
 using JDBC-ODBC Bridge 
 */ 
  

public class inquiry_b extends Applet { 

  T3Client t3 = null; 
  Connection conn = null; 

  TextArea ta; 
  Label lb; 
  TextField searchfield; 
  Button submit_button; 

  public void init() { 

    Panel p1; 

    setLayout(new BorderLayout()); 

    lb = new Label("Title to be searched : "); 
    searchfield = new TextField(30); 

    ta = new TextArea(12, 50); 

    submit_button = new Button("Go"); 

    p1 = new Panel(); 
    p1.add(lb); 
    p1.add(searchfield); 
    p1.add(submit_button); 
  

    add("North", p1); 
    add("South", ta); 

  } 
  

  public boolean action(Event e, Object obj) {  

    String search_string, result_string; 

    if (e.target == submit_button) 
    { 
      search_string = searchfield.getText(); 
      ta.setText(""); 

      if (search_string.length() == 0) 
      { 
        ta.setText("Pls enter a search string!"); 
        ta.show(); 
        return true; 
      } 

      result_string = 
          search_title(search_string); 

      if (result_string != null) { 
         ta.appendText(result_string); 
         return true; 
      } else { 
         return false; 
      } 
    } 

    return false; 
   
  } 

  public void stop() { 
    try {conn.close();}    catch (Exception e) {;} 
    try {t3.disconnect();} catch (Exception e) {;} 
  } 

  void establish() { 

    try { 

      t3 = new 
       T3Client("t3://cobam.ccs.np.ac.sg:7001"); 
      t3.connect(); 
       
      Properties dbproperties = new Properties(); 
      dbproperties.put("user", "sa"); 
      dbproperties.put("password", ""); 
    
      Properties t3properties = new Properties(); 
      t3properties.put("weblogic.t3", t3); 
      t3properties.put("weblogic.t3.dbprops", 
        dbproperties); 
      t3properties.put("weblogic.t3.driverClassName", 
        "sun.jdbc.odbc.JdbcOdbcDriver"); 
      t3properties.put("weblogic.t3.driverURL", 
        "jdbc:odbc:TestSQL"); 
       
      Class.forName("weblogic.jdbc.t3client.Driver"); 
      conn = 
       DriverManager.getConnection("jdbc:weblogic:t3client", 
          t3properties); 

    } catch (Exception e) { 
      e.printStackTrace(); 
    } 

 } 
       

 String search_title(String title_string) { 

    String str; 
    StringBuffer sb1 = new StringBuffer(); 
    int counter; 

    if ((t3 == null) || (conn == null)) { 
       establish(); 
    } 

    if ((t3 != null) && (conn != null)) { 
        str = 
          new String("select * from book where title like '%"+title_string+"%'"); 
         
        try { 
           Statement stmt = conn.createStatement(); 

           stmt.execute(str); 
           ResultSet rs = stmt.getResultSet(); 
           counter = 0; 

           while(rs.next()) { 
             counter++; 
             sb1.append(counter+ 
                ") Catalogue No. :  "+ 
                rs.getString("catalogue_no")+ 
                "\n"+ 
                "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"+ 
                "Title     :"+ 
                rs.getString("title")+ 
                "\n"+ 
                "Author    :"+ 
                rs.getString("major_author")+ 
                "\n"+ 
                "Publisher :"+ 
                rs.getString("publisher")+ 
                "\n"+ 
                "Unit Price:"+ 
                rs.getString("unit_price")+ 
                "\n\n"); 
             
           } 

           if (counter == 0) { 
              return("No matching title !"); 
           } else { 
              return(sb1.toString()); 
           } 

        } catch(Exception exception) { 
          return("SQL query Error"); 
        } 

    } else { 
      return(null); 
    } 

  } 

} 

Listing 4.
 
<html> 
<head> 
<title>Fantastic Reading Book Store</title> 
</head> 

<body> 
<img src=logo.gif> 
<APPLET CODEBASE="http://cobam.ccs.np.ac.sg/" 
 CODE="kiosk.inquiry_b.class" 
width=500 height=240> 
</APPLET> 
</body> 
</html> 


 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.