Where can I find a beans like excel table,or "Microsoft Office Web Compent"
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Qin_Ji
Posted On:   Wednesday, April 25, 2001 08:35 PM

Where can I find a beans like excel table,or "Microsoft Office Web Compent"

Re: Where can I find a beans like excel table,or "Microsoft Office Web Compent"

Posted By:   jini_shans  
Posted On:   Thursday, June 21, 2001 06:17 AM

Hi,

You can use the foll. code to fetch


data from a RDBMS and send to


an applet and display it as a


JTable. The Java Code also given


below...Compile the Java


Applet and place both the files


in ur server to run the program...



This gets the resunt and converts into

string and passes to the applet


JSP CODE





<%@ page import="java.sql.*,java.util.Vector" %> Swing Table Applet <% Vector dataVector = new Vector(); Vector dataVector2 = new Vector(); Vector colNames = new Vector(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:dsnName","userName","passWord"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from emp"); int i=0,j=0; String tmpCode=null,tmpName=null; ResultSetMetaData rsm = rs.getMetaData(); int rsmCount = rsm.getColumnCount(); while (rs.next()) { dataVector2 = new Vector(); colNames = new Vector(); for (int ix=1;ix<=rsmCount;ix++) { dataVector2.addElement(rs.getString(ix)); colNames.addElement(rsm.getColumnName(ix)); } dataVector.addElement(dataVector2); } rs.close();con.close(); } catch(Exception e) { System.out.println(e.getMessage()); } %> </COMMENT> No Java 2 SDK, Standard Edition v 1.3 support for APPLET!!


JAVA CODE...





import javax.swing.*; import javax.swing.table.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.Dimension; import java.util.Vector; import java.util.StringTokenizer; /* */ public class Jsp2JTableApplet extends JApplet{ Vector dataVector = new Vector(); Vector dataVector2 = new Vector(); Vector colNames = new Vector(); // public Jsp2JTableApplet() { public void init() { //Get the Values of the Column Names and the respective Data from the JSP String overallDataString = getParameter("dataString"); String overallColumnString = getParameter("columnNames"); // String overallColumnString = "[SOM_CODE, SOM_NAME]"; // String overallDataString = "[[1001, XXX], [1002, AXW], [1003, Arunachal Group], [1004, aaaaa], [1005, SSSSS], [1006, sdsdsdsdds], [1007, fdfdfdfd], [1008, sdfsdsd], [1009, dsfdsfdsf], [1010, fdsgfdgfdg], [1011, dfsfd], [1012, sdfsdfdsf], [1013, sdsdsdasad], [1014, sadfsdfdsfds], [1015, sdafsdfds], [1016, esdfrsdfdsfds], [1017, sssss], [1018, AXXX], [1019, xz], [1020, dsdsdssd], [1000, JUST], [1021, retertretret], [1022, sdfdsfsdssd], [1023, 776], [1024, ggfgf], [1025, tgfggfgf], [1026, ghh], [1027, qws], [1028, DSAFDSFDSF], [1029, sdfdsfdsf], [1030, sddsds], [1031, SDSDD], [1032, SDSDD], [1033, trreter], [1034, ffdffd], [1035, fddf], [1036, sdfsdfdsfs], [1037, sdfsdfdsfs], [1038, fd], [1039, ww], [1040, fdgfdg], [1041, ax], [1043, dsfdsfds], [1044, rds]]"; String localString = null,fieldString=null; int lastIndexPosition = -1; StringTokenizer mainStringToken = new StringTokenizer(overallDataString,"]"); StringTokenizer localStringToken = null; StringTokenizer mainColumnToken = new StringTokenizer(overallColumnString,","); StringTokenizer localColumnToken = null; // To Convert Record values while (mainStringToken.hasMoreElements()) { localString = mainStringToken.nextElement().toString(); localStringToken = new StringTokenizer(localString,","); dataVector2 = new Vector(); while (localStringToken.hasMoreElements()) { fieldString = localStringToken.nextElement().toString().trim(); lastIndexPosition = fieldString.lastIndexOf("["); if (lastIndexPosition != -1) dataVector2.addElement(fieldString.substring(lastIndexPosition+1)); else dataVector2.addElement(fieldString); } dataVector.addElement(dataVector2); } // To Convert Column Names while (mainColumnToken.hasMoreElements()) { fieldString = mainColumnToken.nextElement().toString().trim(); lastIndexPosition = fieldString.lastIndexOf("["); if (lastIndexPosition != -1) colNames.addElement(fieldString.substring(lastIndexPosition+1)); else colNames.addElement(fieldString); } if (colNames !=null) { String lastColumnName = colNames.elementAt(colNames.size()-1).toString(); String afterRemovedBrace = lastColumnName.indexOf("]")==-1?lastColumnName:lastColumnName.substring(0,lastColumnName.length()-1); colNames.setElementAt(afterRemovedBrace,colNames.size()-1); } JTable Jsp2Table = new JTable(dataVector,colNames); JScrollPane scrollpane = new JScrollPane(Jsp2Table); getContentPane().add(scrollpane); } }


Compile, Run and Enjoy...




jinishans@yahoo.com
About | Sitemap | Contact