Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Applet how to access database in applet

Have Programming Question? Ask it here!
 
 
 


Kunal ghosh
how to access database in applet
0 Answer(s)      2 years and 4 months ago
Posted in : Applet


HI... I'm having an applet where we should display the database values in the applet... It works fine in the local system(same network)... but when its in the server, we r getting null values in the local system.. I created a policy file and also added that url in java.security but came error below... java.sql.SQLException: JZ006: Caught IOException: java.net.UnknownHostException: ICEBOX55 at com.sybase.jdbc3.jdbc.ErrorMessage.raiseError(Unknown Source) at com.sybase.jdbc3.jdbc.ErrorMessage.raiseErrorCheckDead(Unknown Source) at com.sybase.jdbc3.tds.Tds.a(Unknown Source) at com.sybase.jdbc3.tds.Tds.a(Unknown Source) at com.sybase.jdbc3.tds.Tds.login(Unknown Source) at com.sybase.jdbc3.jdbc.SybConnection.a(Unknown Source) at com.sybase.jdbc3.jdbc.SybConnection.handleHAFailover(Unknown Source) at com.sybase.jdbc3.jdbc.SybConnection.(Unknown Source) at com.sybase.jdbc3.jdbc.SybConnection.(Unknown Source) at com.sybase.jdbc3.jdbc.SybDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at QueryBuilderApplet$1.run(QueryBuilderApplet.java:221) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)

my code is :

import java.awt.KeyboardFocusManager; import java.awt.event.KeyEvent; import java.awt.Cursor; import java.io.InputStream; import java.io.ObjectInputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.HashMap; import java.util.HashSet; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger;

//Imports for getDataClass import java.sql.*; import sun.jdbc.odbc.JdbcOdbcDriver;

import javax.swing.JApplet; import javax.swing.JOptionPane; import javax.swing.KeyStroke; import javax.swing.UIManager; import javax.swing.table.DefaultTableModel;

import netscape.javascript.JSObject; import netscape.javascript.JSException;

import com.adbs.metadata.JdbcMetadataProvider; import com.adbs.querybuilder.Parameter; import com.adbs.querybuilder.ParameterList; import com.adbs.querybuilder.PlainTextSQLBuilder; import com.adbs.querybuilder.QueryBuilderException; import com.adbs.querybuilder.SQLUpdatedEvent; import com.adbs.querybuilder.SQLUpdatedEventListener; import com.adbs.syntax.AutoSyntaxProvider; import com.adbs.syntax.DB2SyntaxProvider; import com.adbs.syntax.MSSQLSyntaxProvider; import com.adbs.syntax.MySQLSyntaxProvider; import com.adbs.syntax.OracleSyntaxProvider; import com.adbs.syntax.PostgreSQLSyntaxProvider; import com.adbs.syntax.SybaseSyntaxProvider; //import com.google.gwt.user.client.ui.MouseListener; import com.adbs.syntax.UniversalSyntaxProvider;

public class QueryBuilderApplet extends JApplet {

private JSObject win;
private String connServer;
private String connName;
private String query;
private String connId;
private String le;
private String repoName;

private String connUrl;
private String driver;
private String userName;
private String passWord;
private com.adbs.querybuilder.QueryBuilder queryBuilder1;
private JdbcMetadataProvider metadataProvider = new JdbcMetadataProvider();
private static final long serialVersionUID = 1L;

private PlainTextSQLBuilder plainTextSQLBuilder1 = new PlainTextSQLBuilder();

private String list;


public String getQuery(){
    list="No-List";
            list = queryBuilder1.getSQL();
    return list;
}

@Override


public void init() {
    System.out.println(">>>>>>>>>>>> init()  >>>>>>");
    connServer = getParameter("type");
    connName = getParameter("name");
    query = getParameter("qry");
    connId = getParameter("connId");
    le = getParameter("le");
    repoName =getParameter("repoName");
    win = JSObject.getWindow(this);
    //final String modifiedQuery;
    System.out.println(">>>>>>>>>>>> type  >>>>>> "+connServer);
    //System.out.println(">>>>>>>>>>>> name  >>>>>> "+connName);
    System.out.println(">>>>>>>>>>>> Query  >>>>>> "+query);

// modifiedQuery = getModifiedQuery(query); // System.out.println(">>>>>>>>>>>> NewQry >>>>>> "+modifiedQuery);

    final StringBuffer metaData = new StringBuffer();   
    metaData.append(getMetadataFileObject( connServer, connName));
    final HashMap hsp = getConnParameters (repoName, le, connId);
    //final String connString = (String) hsp.get("setURL");
    connUrl = (String) hsp.get("setURL");
    driver = (String)hsp.get("setDriver");
    userName = (String)hsp.get("setUserName");
    passWord = (String)hsp.get("setPassword");
    //System.out.println("URLLLLLLLLLLLLL ::::::: "+connString);
    System.out.println("setDriverrrrrrrr ::::::: "+(String)hsp.get("setDriver"));
    //System.out.println("passwoooordddddd ::::::: "+(String)hsp.get("setPassword"));

    try
        {
            java.awt.EventQueue.invokeAndWait(new Runnable()
            {
                public void run()
                {
                    // set native Look'n'Feel
                    try
                    {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    }
                    catch (Exception ex)
                    {
                        System.out.println(ex.getMessage());
                    }

                    //init();
                    initComponents();

                    if ("oracle".equalsIgnoreCase(connServer))
                     {

                        try{
                            Class.forName(driver).newInstance();
                        }catch(Exception e){
                        }try{   
                            metadataProvider.setConnection(DriverManager.getConnection(connUrl, userName,passWord));
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                        queryBuilder1.setMetadataProvider(metadataProvider);
                        OracleSyntaxProvider syntaxProvider = new OracleSyntaxProvider();
                        queryBuilder1.setSyntaxProvider(syntaxProvider);


                     } else if ("ODBC".equalsIgnoreCase(connServer))
                     {

                         try{
                                Class.forName(driver).newInstance();
                            }catch(Exception e){
                            }try{   
                                metadataProvider.setConnection(DriverManager.getConnection(connUrl, userName,passWord));
                            } catch (SQLException e) {
                                e.printStackTrace();
                            } 
                         queryBuilder1.setMetadataProvider(metadataProvider);
                         AutoSyntaxProvider syntaxProvider = new AutoSyntaxProvider();
                         queryBuilder1.setSyntaxProvider(syntaxProvider);

                     } else if ("mssql".equalsIgnoreCase(connServer))
                     {

                         try{
                                Class.forName(driver).newInstance();
                            }catch(Exception e){
                            }try{   
                                metadataProvider.setConnection(DriverManager.getConnection(connUrl, userName,passWord));
                            } catch (SQLException e) {
                                e.printStackTrace();
                            } 
                         queryBuilder1.setMetadataProvider(metadataProvider);
                         MSSQLSyntaxProvider syntaxProvider = new MSSQLSyntaxProvider();
                         queryBuilder1.setSyntaxProvider(syntaxProvider);

                     } else if ("mysql".equalsIgnoreCase(connServer))
                     {
                         try{
                                Class.forName(driver).newInstance();
                            }catch(Exception e){
                            }try{   
                                metadataProvider.setConnection(DriverManager.getConnection(connUrl, userName,passWord));
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
                         queryBuilder1.setMetadataProvider(metadataProvider);
                         MySQLSyntaxProvider syntaxProvider = new MySQLSyntaxProvider();
                         queryBuilder1.setSyntaxProvider(syntaxProvider);

                     } else if ("db2".equalsIgnoreCase(connServer))
                     {

                         try{
                                Class.forName(driver).newInstance();
                            }catch(Exception e){
                            }try{   
                                metadataProvider.setConnection(DriverManager.getConnection(connUrl, userName,passWord));
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
                         queryBuilder1.setMetadataProvider(metadataProvider);
                         DB2SyntaxProvider syntaxProvider = new DB2SyntaxProvider();
                         queryBuilder1.setSyntaxProvider(syntaxProvider);

                     } else if ("postgres".equalsIgnoreCase(connServer))
                     {

                         try{
                                Class.forName(driver).newInstance();
                            }catch(Exception e){
                            }try{   
                                metadataProvider.setConnection(DriverManager.getConnection(connUrl, userName,passWord));
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
                         queryBuilder1.setMetadataProvider(metadataProvider);
                         PostgreSQLSyntaxProvider syntaxProvider = new PostgreSQLSyntaxProvider();
                         queryBuilder1.setSyntaxProvider(syntaxProvider);
                     } else if("sybase".equalsIgnoreCase(connServer))
                     {

                         try{
                                Class.forName(driver).newInstance();
                            }catch(Exception e){
                            }try{   
                                metadataProvider.setConnection(DriverManager.getConnection(connUrl, userName,passWord));
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
                         queryBuilder1.setMetadataProvider(metadataProvider);   
                         SybaseSyntaxProvider syntaxProvider = new SybaseSyntaxProvider();
                         queryBuilder1.setSyntaxProvider(syntaxProvider);
                     }else if ("Hsql".equalsIgnoreCase(connServer))
                     {
                        //String url= connString.replace(";","/");

                         try{
                                Class.forName(driver).newInstance();
                            }catch(Exception e){
                            }try{   
                                metadataProvider.setConnection(DriverManager.getConnection(connUrl, userName,passWord));
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
                         queryBuilder1.setMetadataProvider(metadataProvider);
                         AutoSyntaxProvider syntaxProvider = new AutoSyntaxProvider();
                         queryBuilder1.setSyntaxProvider(syntaxProvider);

                     }else if ("TERADATA".equalsIgnoreCase(connServer))
                     {

                             try{
                                    Class.forName(driver).newInstance();
                                }catch(Exception e){
                                }try{   
                                    metadataProvider.setConnection(DriverManager.getConnection(connUrl, userName,passWord));
                                } catch (SQLException e) {
                                    e.printStackTrace();
                                }
                             queryBuilder1.setMetadataProvider(metadataProvider);
                             AutoSyntaxProvider syntaxProvider = new AutoSyntaxProvider();
                             queryBuilder1.setSyntaxProvider(syntaxProvider);

                         }
                    //set up SQL builder:
                    plainTextSQLBuilder1.setQueryBuilder(queryBuilder1);

                    // handle the notification from plainTextSQLBuilder1 about the query text has been changed
                    plainTextSQLBuilder1.addSQLUpdatedEventListener(new SQLUpdatedEventListener()
                    {
                        @Override
                        public void sqlUpdatedEventOccurred(SQLUpdatedEvent event)
                        {
                            try
                            {
                                jTextPane1.setText(plainTextSQLBuilder1.getSQL());
                            }
                            catch (QueryBuilderException ex)
                            {
                                JOptionPane.showMessageDialog(QueryBuilderApplet.this, ex.getMessage());
                            }
                        }
                    });

                    // Load metadata from XML file located in resources (for demonstration purposes)
                    try
                    {
                        queryBuilder1.getMetadataContainer().loadFromXML(metaData.toString()); //sb.toString()

                        System.out.println("applet @176  : Write successfully.......");

                    }
                    catch (Exception ex)
                    {
                        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
                        JOptionPane.showMessageDialog(QueryBuilderApplet.this, ex.getMessage());
                    }
                 if (!("".equals(query))){
                        try
                        {
                            queryBuilder1.setSQL(query);
                        }
                        catch (QueryBuilderException ex)
                        {
                            JOptionPane.showMessageDialog(QueryBuilderApplet.this, ex.getMessage());
                        }
                }
                    // force the jTextPane1 to move the focus on the Tab key:
                    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
                    HashSet keystrokes = new HashSet();
                    keystrokes.add(tab);
                    jTextPane1.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keystrokes);

                    KeyStroke shiftTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK);
                    keystrokes = new HashSet();
                    keystrokes.add(shiftTab);
                    jTextPane1.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keystrokes);
                }
            });
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }

    }

 public String getMetadataFileObject (String connServer, String connName)
    {
        System.out.println(">>>>>>>>>>>> getMetadataFileObject() >>>>>>");
        System.out.println("connServer  "+connServer+" cccName  "+connName);
        Vector classObj = new Vector();
        String result="";
        try {

            InputStream urlInput =null;
            HttpURLConnection con =null;

            URL uri=new URL(getCodeBase(),"GetMetaDataFile?CONN_TYPE="+URLEncoder.encode(connServer)+"&CONN_NAME="+URLEncoder.encode(connName));

            con =(HttpURLConnection)uri.openConnection();
            con.setDoInput(true);
            con.setDoOutput(true);
            con.setUseCaches(false);
            con.setRequestMethod("POST");
            con.setRequestProperty("Accept-Language", "en");
            con.setRequestProperty("content-type", "text/html");
            urlInput=con.getInputStream();
            ObjectInputStream ois=new ObjectInputStream(urlInput);
            Object obj= ois.readObject();

            String fileStr = (String)obj;
            /*
            File fname = new File("C:"+File.separator+"ice_store"+File.separator+"data"+File.separator+"metadata");
            if (!fname.exists()){
                //System.out.println("CREatingggggggggggggggggggggg:::::::::::::::::::::::::");
                fname.mkdirs();
            }   
            String fileName = fname+File.separator+connName+".xml";
            byte[] fileStream = fileStr.getBytes();
            FileOutputStream fos = new FileOutputStream(fileName);

            fos.write(fileStream);
            fos.flush();
            fos.close();
            */
            result = fileStr;
            System.out.println("Received MetaData conetent displaying...");
            urlInput.close();
        } catch (Exception e)
        {
            e.printStackTrace();
        }

        return result;
    }

    private void FillTableFromResultSet(final ResultSet resultSet)
    {
        try
        {
            ResultSetMetaData metaData = resultSet.getMetaData();

            int columnCount = metaData.getColumnCount();

            Vector columns = new Vector(columnCount);

            //store column names
            for (int i = 1; i <= columnCount; i++)
            {
                columns.add(metaData.getColumnName(i));
            }

            Vector data = new Vector();
            Vector row;

            //store row data
            while (resultSet.next())
            {
                row = new Vector(columnCount);

                for (int i = 1; i <= columnCount; i++)
                {
                    row.add(resultSet.getString(i));
                }

                data.add(row);
            }

            jTable1.setModel(new DefaultTableModel(data, columns));
        }
        catch (SQLException ex)
        {
            Logger.getLogger(QueryBuilderApplet.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents

    private void initComponents() {

 jTabbedPane1 = new javax.swing.JTabbedPane();
 jSplitPane1 = new javax.swing.JSplitPane();
 jScrollPane1 = new javax.swing.JScrollPane();
 jTextPane1 = new javax.swing.JTextPane();
 queryBuilder1 = new com.adbs.querybuilder.QueryBuilder();
 dataPanel = new javax.swing.JPanel();
 jScrollPane2 = new javax.swing.JScrollPane();
 jTable1 = new javax.swing.JTable();
 jPanel1 = new javax.swing.JPanel();
 jButtonSave = new javax.swing.JButton();
 jButtonCancel = new javax.swing.JButton();

 setStub(null);

 jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
     public void stateChanged(javax.swing.event.ChangeEvent evt) {

         jTabbedPane1StateChanged(evt);
     }
 });

 jSplitPane1.setDividerLocation(450);
 jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
 jSplitPane1.setResizeWeight(1.0);
 jSplitPane1.setRightComponent(jScrollPane1);
 jSplitPane1.setLeftComponent(queryBuilder1);
 jSplitPane1.setRightComponent(jScrollPane1);

 jTextPane1.setFont(new java.awt.Font("Monospaced", 0, 12));
 jTextPane1.setDropTarget(null);
 jTextPane1.addFocusListener(new java.awt.event.FocusAdapter() {
     public void focusLost(java.awt.event.FocusEvent evt) {

        jTextPane1FocusLost(evt);
     }
 });
 jScrollPane1.setViewportView(jTextPane1);

 getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

 jTabbedPane1.addTab("SQL", jSplitPane1);

 dataPanel.setLayout(new javax.swing.BoxLayout(dataPanel, javax.swing.BoxLayout.LINE_AXIS));

 jTable1.setModel(new javax.swing.table.DefaultTableModel(
     new Object [][] {
         {null, null, null, null},
         {null, null, null, null},
         {null, null, null, null},
         {null, null, null, null}
     },
     new String [] {
         "Title 1", "Title 2", "Title 3", "Title 4"
     }
 ));
 jScrollPane2.setViewportView(jTable1);

 dataPanel.add(jScrollPane2);

 jTabbedPane1.addTab("Data", dataPanel);
 getContentPane().add(jTabbedPane1);

 jButtonSave.setText("SAVE");
 jButtonSave.addActionListener(new java.awt.event.ActionListener() {
     public void actionPerformed(java.awt.event.ActionEvent evt) {
         jButtonSaveActionPerformed(evt);
     }
 });


 jButtonCancel.setText("CANCEL");
 jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
     public void actionPerformed(java.awt.event.ActionEvent evt) {
         evt.setSource(query);
         jButtonCancelActionPerformed(evt);
     }
 });

javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(jPanel1);
 jPanel1.setLayout(panel1Layout);
 panel1Layout.setHorizontalGroup(
     panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
         .addContainerGap(1025, Short.MAX_VALUE)
         .addComponent(jButtonSave, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addGap(18, 18, 18)
         .addComponent(jButtonCancel)
         .addGap(18, 18, 18))
 );
 panel1Layout.setVerticalGroup(
     panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
         .addComponent(jButtonSave)
         .addComponent(jButtonCancel))
 );

getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_START);

}

/* private void initComponents() {

    jSplitPane1 = new javax.swing.JSplitPane();
 queryBuilder1 = new com.adbs.querybuilder.QueryBuilder();
 jScrollPane1 = new javax.swing.JScrollPane();
 jTextPane1 = new javax.swing.JTextPane();
 jPanel1 = new javax.swing.JPanel();
 jPanel2 = new javax.swing.JPanel();
 jButtonSave = new javax.swing.JButton();
 jButtonCancel = new javax.swing.JButton();

 setStub(null);

 jSplitPane1.setDividerLocation(450);
 jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
 jSplitPane1.setResizeWeight(1.0);
 jSplitPane1.setLeftComponent(queryBuilder1);

 jTextPane1.setFont(new java.awt.Font("Monospaced", 0, 12));
 jTextPane1.addFocusListener(new java.awt.event.FocusAdapter() {
     public void focusLost(java.awt.event.FocusEvent evt) {
         jTextPane1FocusLost(evt);
     }
 });
 jScrollPane1.setViewportView(jTextPane1);

 jSplitPane1.setRightComponent(jScrollPane1);

 getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

 jPanel1.setPreferredSize(new java.awt.Dimension(821, 30));
 jPanel1.setLayout(new java.awt.BorderLayout());

 jPanel2.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647));
 jPanel2.setPreferredSize(new java.awt.Dimension(821, 30));

 jButtonSave.setText("SAVE");
 jButtonSave.setActionCommand("SAVE");
 jButtonSave.addActionListener(new java.awt.event.ActionListener() {
     public void actionPerformed(java.awt.event.ActionEvent evt) {
         jButtonSaveActionPerformed(evt);
     }
 });

 jButtonCancel.setText("CANCEL");
 jButtonCancel.setActionCommand("CANCEL");
 jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
     public void actionPerformed(java.awt.event.ActionEvent evt) {
        evt.setSource(query);
         jButtonCancelActionPerformed(evt);
     }
 });

 javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
 jPanel2.setLayout(jPanel2Layout);
 jPanel2Layout.setHorizontalGroup(
     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
         .addContainerGap(603, Short.MAX_VALUE)
         .addComponent(jButtonSave, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
         .addComponent(jButtonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addContainerGap())
 );
 jPanel2Layout.setVerticalGroup(
     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
         .addComponent(jButtonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(jButtonSave, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
 );

 jPanel1.add(jPanel2, java.awt.BorderLayout.CENTER);

 getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_START);

}// //GEN-END:initComponents//

*/    

private void jTextPane1FocusLost(java.awt.event.FocusEvent evt)                                     
    {                                         
        // when the focus is going out of the text pane, update the query builder with new query text
        try
        {
            queryBuilder1.setSQL(jTextPane1.getText());
        }
        catch (QueryBuilderException ex)
        {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }           

private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt)
{

 System.out.println("  T2222222222222222222222");
 if (jTabbedPane1.getSelectedComponent() == dataPanel)
    {
        System.out.println("  T33333333333333333333333");
        // clear JTable
        jTable1.setModel(new DefaultTableModel(new Vector(), new Vector()));

        // Update the query text in the query builder.
        // this because the StateChanged event of the TabbedPane arrives before the JTextPane1 lost the focus
        // and updates the query text.
        try
        {
            queryBuilder1.setSQL(jTextPane1.getText());
        }
        catch (QueryBuilderException ex)
        {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, ex.getMessage());
            return;
        }

        // execute query:

        JdbcMetadataProvider metadataProvider = (JdbcMetadataProvider) queryBuilder1.getMetadataProvider();

        System.out.println("getmetadataprovider   : >>>"+metadataProvider);
        if (queryBuilder1.getMetadataProvider() != null && queryBuilder1.getMetadataProvider().isConnected())
        {

                        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            try
            {
                ResultSet resultSet = null;
                ParameterList parameters = queryBuilder1.getParameters();

                // if query contains parameters...
                if (parameters != null && parameters.getCount() > 0)
                {
                    // prepare statement
                    PreparedStatement statement = metadataProvider.getConnection().prepareStatement(queryBuilder1.getSQL());

                    // ...ask user for parameter values:
                    for (int i = 0; i < parameters.getCount() ; i++)
                    {
                        Parameter p = parameters.get(i);
                        String message = "Please enter value for query parameter #" + String.valueOf(i + 1) + ":" +
                                "\nname: " + p.getFullName() +
                                "\ntype: " + typeToString(p.getDataType());

                        // ask for parameter value
                        String value = JOptionPane.showInputDialog(this, message, "Enter value for parameter",
                                JOptionPane.QUESTION_MESSAGE);

                        if (value != null)
                        {
                            //set entered parameter value to the prepared statement
                            statement.setObject(i + 1, value, p.getDataType());
                        }
                    }

                    statement.execute();
                    resultSet = statement.getResultSet();
                }
                else // just execute the query
                {
                    resultSet = metadataProvider.getConnection().createStatement().executeQuery(queryBuilder1.getSQL());
                }

                // fill JTable
                FillTableFromResultSet(resultSet);
            }
            catch (SQLException ex)
            {
                Logger.getLogger(QueryBuilderApplet.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this, ex.getMessage());
            }
            finally
            {
                setCursor(Cursor.getDefaultCursor());
            }

        }    
    }
}


    private void jButtonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
            // TODO add your handling code here:
        try
        {
            queryBuilder1.setSQL(jTextPane1.getText());
            System.out.println("this>>>>>>>>>>>> 1111:"+this);
            System.out.println(" Save Print : >> " +queryBuilder1.getSQL());
            if(win != null){
             try{
                String command = evt.getActionCommand();
                System.out.println("Command>>>>>>>>>>>> :"+command);

                    //System.out.println("this>>>>>>>>>>>>222 :"+this);
                    //win.eval("window.close();");
                    String query = queryBuilder1.getSQL();
                    win.call("getSqlQuery", new String[]{query});

             }catch(JSException ex){
                 ex.printStackTrace();
             }
            }
        }
        catch (QueryBuilderException ex)
        {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
   }//GEN-LAST:event_jButton1ActionPerformed


   private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
            // TODO add your handling code here:
            System.out.println(">>>>>>   "+evt.getSource());
            queryBuilder1.setSQL(evt.getSource().toString());
            System.out.println(" Cancel Print : >> " +queryBuilder1.getSQL());
            if(win != null){
              try{
                //JSObject win = JSObject.getWindow(null);
                    //win.eval("window.close();");
                String query = queryBuilder1.getSQL();
                win.call("getSqlQuery", new String[]{query});
              }catch(JSException ex){
                 ex.printStackTrace();
              }
            }
    }//GEN-LAST:event_jButton3ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JPanel dataPanel;

    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JButton jButtonSave;
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;

    // End of variables declaration 

    public HashMap getConnParameters (String repoName, String legalEntityID,String connID)
 {
     System.out.println("--getConnParameters--");
        HashMap hsp = new HashMap();
     try {
         InputStream urlInput =null;
         HttpURLConnection con =null;
         URL uri=new URL(getCodeBase(),"QueryBuilderConninfoGrabber?CONN="+connID+"&RN="+URLEncoder.encode(repoName)+"&LE="+legalEntityID);
         con =(HttpURLConnection)uri.openConnection();
         con.setDoInput(true);
         con.setDoOutput(true);
         con.setUseCaches(false);
         con.setRequestMethod("POST");
         con.setRequestProperty("Accept-Language", "en");
         con.setRequestProperty("content-type", "text/html");
         urlInput=con.getInputStream();
         ObjectInputStream ois=new ObjectInputStream(urlInput);
         Object obj= ois.readObject();
         hsp=(HashMap) obj;
     } catch (Exception e)
     {
         e.printStackTrace();
     }
     return hsp;
 }

    public static String typeToString(int sqlType)
    {
        switch (sqlType)
        {
            case Types.ARRAY: return "ARRAY";
            case Types.BIGINT: return "BIGINT";
            case Types.BINARY: return "BINARY";
            case Types.BIT: return "BIT";
            case Types.BLOB: return "BLOB";
            case Types.BOOLEAN: return "BOOLEAN";
            case Types.CHAR: return "CHAR";
            case Types.CLOB: return "CLOB";
            case Types.DATALINK: return "DATALINK";
            case Types.DATE: return "DATE";
            case Types.DECIMAL: return "DECIMAL";
            case Types.DISTINCT: return "DISTINCT";
            case Types.DOUBLE: return "DOUBLE";
            case Types.FLOAT: return "FLOAT";
            case Types.INTEGER: return "INTEGER";
            case Types.JAVA_OBJECT: return "JAVA_OBJECT";
            case Types.LONGNVARCHAR: return "LONGNVARCHAR";
            case Types.LONGVARBINARY: return "LONGVARBINARY";
            case Types.LONGVARCHAR: return "LONGVARCHAR";
            case Types.NCHAR: return "NCHAR";
            case Types.NCLOB: return "NCLOB";
            case Types.NULL: return "NULL";
            case Types.NUMERIC: return "NUMERIC";
            case Types.NVARCHAR: return "NVARCHAR";
            case Types.OTHER: return "OTHER";
            case Types.REAL: return "REAL";
            case Types.REF: return "REF";
            case Types.ROWID: return "ROWID";
            case Types.SMALLINT: return "SMALLINT";
            case Types.SQLXML: return "SQLXML";
            case Types.STRUCT: return "STRUCT";
            case Types.TIME: return "TIME";
            case Types.TIMESTAMP: return "TIMESTAMP";
            case Types.TINYINT: return "TINYINT";
            case Types.VARBINARY: return "VARBINARY";
            case Types.VARCHAR: return "VARCHAR";
            default: return "UNKNOWN";
        }
    }

}


Advertisement
View Answers

Related Tutorials/Questions & Answers:
how to access database in applet
how to access database in applet  HI... I'm having an applet where we should display the database values in the applet... It works fine in the local system(same network)... but when its in the server, we r getting null values
Applet database access - Applet
Applet database access  HI... I'm having an applet where we should display the database values in the applet... It works fine in the local system... no change... How to implement this...?? thanks in advance
Advertisements
applet connected to table in MS Access database
applet connected to table in MS Access database   i have connected my java code with the MS access database and this is my code, can anyone tell me how to show the table in an applet...pls import java.sql.
how to access the MS ACCESS database with java
how to access the MS ACCESS database with java   how to access the MS ACCESS database with java how can we insert,delete,update,search records of ms access with java   Java MS Access database connectivity Follow
how to add database in Java Applet
how to add database in Java Applet  hi every java master or Java Professional my name is vincent i'm java beginners hope u all can ,tech me how to add database in Java Applet below this code is my applet source code . thank
how to access the MS ACCESS database with java - Java Beginners
how to access the MS ACCESS database with java  how can we insert,delete,update,search records of ms access with java
How to access (MySQL)database from J2ME?
How to access (MySQL)database from J2ME?  I am new to J2ME. I am using NetBeans. Can anyone help me? How to access (MySQL)database from J2ME? ( I search a lot I found that there is need to access database through servlet
how to delete the access database value in jsp
how to delete the access database value in jsp  i loaded my database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from database
how to delete the access database value in jsp
how to delete the access database value in jsp  i loaded my database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from database
how to connect to MS access database in JSP?
how to connect to MS access database in JSP?  how to connect to MS access database in JSP? Any seetings/drivers need to be set or installed before... and select the driver Microsoft Access Driver(*.mdb). 3)After selecting the driver
How To Connect MS ACCESS 2003 Database in C Program with Graphics.
How To Connect MS ACCESS 2003 Database in C Program with Graphics.  How To Connect MS ACCESS 2003 Database in C Program with Graphics
Applet to database error - Applet
Applet to database error  Hi... I had an application where i need to connect to the database for the values to display in the applet.... Following... Applet implements MouseListener{ boolean rect1Clicked,rect1Clicked1,mouseEntered
How to Store Float Value into Access Database - Java Beginners
How to Store Float Value into Access Database  Hello sir,I want to Store Student Marks Percentage into Access Database in Float Value how i can Store.... To store the double value in Access database, you need to set the datatype
how to retrieve data into combo from database in java applet?
how to retrieve data into combo from database in java applet?  hi,. i have written applet codes for linking two frames and database connectivity but the problem is, the database is not retrieving data into the combo..please
how to run applet - Applet
how to run applet   Hi everybody i am using connecting jdbc in applet program. this is executed successfully with appletviewer command >... how can i execute in browser ? Thanks in advance thanks for seeing my
How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to store JComboBox selected Item into Ms Access Database  How to store JComboBox selected Item into Ms Access Database.  Hi Friend...:access","",""); Statement stmt=con.createStatement(); ResultSet rs
How to Open Picture From M.S. Access Database using Java Servlet ?
How to Open Picture From M.S. Access Database using Java Servlet ?  Hi all my Friends I have below code which insert a picture into M.S. Access Database But i m still not able to open this picture through Java using M.S. Access
How To Insert A New Record to MS Access table database in GUI
How To Insert A New Record to MS Access table database in GUI  Hello, I've been working on the actionPerformed part of my java application that involves inserting a record into a 6-column table in my MS Access database table. I'm
How to save JCombobox Selected Item in to Access Database - Java Beginners
How to save JCombobox Selected Item in to Access Database  How to save JCombobox Selected Item in to Access Database  Hi Friend, Try...:access","",""); Statement stmt=con.createStatement(); ResultSet rs
Connect database in Access to Netbean?
Connect database in Access to Netbean?  how to connect database in micrsoft access to Netbean?i know it can be connected by using JDBC-ODBC bridge, can i know the steps in connecting the database? Is there any source code
link hibernate to MS ACCESS database
link hibernate to MS ACCESS database  how to link hibernate to ms access database instead of sql database
how to delete specified coloumn from database(MS Access) by using windows application
how to delete specified coloumn from database(MS Access) by using windows application  how to delete specified coloumn from database(MS Access) by using c# windows application
how to store image file and videofile in ms access database using java? - JDBC
how to store image file and videofile in ms access database using java?  how to store image file and video file in ms access database using java
ACCESS DATABASE FROM HTML
ACCESS DATABASE FROM HTML  I want to access sql 2008 database in html page without help of ADODB connection.. because if access through ADODB means there is a security problem. so, Access database in html page(client side
Access 2007 database connectivity
Access 2007 database connectivity  i design an application form... source and destination. pls tell me the code of connectivity with access 2007 database using JComboBox.thanks
How to insert or delete records in MS access database using jsp - JSP-Servlet
How to insert or delete records in MS access database using jsp  Hi friends please provide me a solution that i insert or delete record from a database using java server pages. I used the microsoft access 2003 database. PlZ
How to Access MS Access in jar.
How to Access MS Access in jar.  how do i access my Ms-Access file... to access it via Code or is their any alter-native?? Do i need any Driver to do this ... i m able to access a Ms-access via JDBC but cant find the file wen
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.
How can I access databse through JSP. I am using postgresql-8.4.4-1-windows as database and jboss-4.0.5.GA as server.  I am using postgresql-8.4.4-1-windows as database, jboss-4.0.5.GA as server and jdk-6-windows-i586 with IDE
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database - Java Beginners
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database  Hello Sir I want Store Corse Type that contains Two JRadioButton I want Store Information from JRadioButton to MS Access Database, and I
connecting to access database
Access Driver(*.mdb) Select database name and Create the DSN name (e.g access...connecting to access database  print("code sample");Hi I Write java... this there is no error but my data is not going to my Acess Database. There is working
how to close the connection object,statement object,resultssetobject when using the microsoft access a database - SQL
how to close the connection object,statement object,resultssetobject when using the microsoft access a database   Hi Friend, I am developing the webapplication using the jsp(business logice-jsp).backend is microsoft access
The JDBC API to access a desktop database like Microsoft Access over the network.
The JDBC API to access a desktop database like Microsoft Access over the network.  How can I use the JDBC API to access a desktop database like Microsoft Access over the network
JSP and Database access
JSP and Database access  Hi, Please help me with the following program. I am not able to update all the pa column values in my database. csea.jsp: <html> <body> <%@page import="java.sql.*"%> <form method
how to retrieve the id value itself from the access database to drop down listbox in jsp
how to retrieve the id value itself from the access database to drop down listbox in jsp  how to retrieves the id which is an int datatype, from access database to drop down list box in jsp...plz send the code for that.....plz
How To Display both image and data into Swing JTable which is retrieved from ms access database
How To Display both image and data into Swing JTable which is retrieved from ms access database  So far this is my code how can i display both image and data from database.. while (rs.next()) { Vector row = new Vector(columns
how i conditional access the data from database using combo box. - JSP-Servlet
how i conditional access the data from database using combo box.   i... appears named Subject values Arts, Commerce, Science. how i conditional access the data from database when i select class 11 0r 12. Here is JSP file
Migrating sql database to Access through coding
Migrating sql database to Access through coding  How can i migrate SQL database(table) to My access through coding
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
how to retreive values from MS Access Database based on the values entered... in MS Access Database. the table structure is Sno JobName ProgramName Problem... in the database fields JobName, ProgramName and Problem whether any single match is found
How to access Subclass?
How to access Subclass?  How to access subclass in java? please tell me the syntex with an example
how to import user-define package to applet - Applet
how to import user-define package to applet  how to import user-define package to applet... can u write a java coding can execute in jdk only...; public class JavaApplet extends Applet{ public static final String DATE
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
Applet
Applet  how to run an applet on a web browser
how to run a applet from browser
how to run a applet from browser  hi, iam sending the code of an applet. it is working in cmd prompt,but not working from browser. <APPLET CODE... to the database con = DriverManager.getConnection(connectionURL, "root", "root
display data from a table in Access Database in a HTML page
display data from a table in Access Database in a HTML page  how to display data from a table in Access Database in a HTML page in a Java Program
how to insert values from jsp into ms access
how to insert values from jsp into ms access   how to insert values using jsp into ms access database
jfreechart display from access database data.
is to be done in a servlet.. Note that it is a access made database. How can I...jfreechart display from access database data.  I have made a database... to retrieve the data from the access database using prepared statement and then display
updating an access database with visual basic 2010
updating an access database with visual basic 2010  I am building a program in visual basic 2010 that connects to an access database. I... the information is entered I need it to update the information in access
How to save image on the server by applet
How to save image on the server by applet  HI, in my project I am using applet and creating a chart by jcchart. Now when the chart has ploated... as a gif image on the server directory. Can any Body help me how can I do it Thanks
How to save image on the server by applet
How to save image on the server by applet  HI, in my project I am using applet and creating a chart by jcchart. Now when the chart has ploated... as a gif image on the server directory. Can any Body help me how can I do it Thanks
retreiving data from microsoft access database
retreiving data from microsoft access database  How can i retrieve data from microsoft access when i have select the vaules in combo box and text box. When i select these values... i want to retrieve the corresponding columns
 

 

 

DMCA.com