Results 1 to 9 of 9
Like Tree3Likes
  • 1 Post By Norm
  • 1 Post By kneitzel
  • 1 Post By SurfMan

Thread: applets problems

  1. #1
    gghgc is offline Member
    Join Date
    May 2014
    Posts
    9
    Rep Power
    0

    Lightbulb applets problems

    hello guys :) i'm trying to store data on my database (postgresql) but it doesn't work.


    my application runs in applet in netbeans ide and data was save in the database.

    but when i run it in the browser when the button to store the values, it doesn't work.
    thank you for your help.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: applets problems

    it doesn't work.
    Please explain.
    Copy the full text of the error messages and paste it here.
    gghgc likes this.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    gghgc is offline Member
    Join Date
    May 2014
    Posts
    9
    Rep Power
    0

    Default Re: applets problems

    Quote Originally Posted by Norm View Post
    Please explain.
    Copy the full text of the error messages and paste it here.
    sir i don't have any errors, its just that when i click the button to save data in my database(postgresql) nothing happens.


    when i run my application using netbeans IDE(applets) the values or data are stored in my database, yet when i run it into the browser no data is saved.
    thank you.

  4. #4
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    6

    Default Re: applets problems

    Hi,
    You should check the code that inserts the data. I guess that you do not handle an error correctly. Maybe you want to post your code.
    And maybe you can describe the whole szenario: which url do you open in your browser? What is your connection string?
    gghgc likes this.

  5. #5
    gghgc is offline Member
    Join Date
    May 2014
    Posts
    9
    Rep Power
    0

    Default Re: applets problems

    here is the copy of my code sir: i have a database = mydb2 and table student

    appler design
    /*
    * To change this license header, choose License Headers in Project Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    */

    package com.in;

    /**
    *
    * @author HGC
    */
    public class DemoNow extends javax.swing.JApplet {

    /**
    * Initializes the applet DemoNow
    */
    @Override
    public void init() {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
    * For details see How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)
    */
    try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
    javax.swing.UIManager.setLookAndFeel(info.getClass Name());
    break;
    }
    }
    } catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(DemoNow.class.g etName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(DemoNow.class.g etName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(DemoNow.class.g etName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(DemoNow.class.g etName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the applet */
    try {
    java.awt.EventQueue.invokeAndWait(new Runnable() {
    public void run() {
    initComponents();
    }
    });
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }

    /**
    * This method is called from within the init() method to initialize the
    * form. WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    txtSample = new javax.swing.JTextField();
    txtFaculty = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    txtName = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    txtCity = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();

    jLabel1.setHorizontalAlignment(javax.swing.SwingCo nstants.RIGHT);
    jLabel1.setText("Name:");

    jLabel2.setHorizontalAlignment(javax.swing.SwingCo nstants.RIGHT);
    jLabel2.setText("Faculty:");

    jButton1.setText("Save");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    }
    });

    jLabel3.setHorizontalAlignment(javax.swing.SwingCo nstants.RIGHT);
    jLabel3.setText("City:");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(40, 40, 40)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(jButton1)
    .addGap(18, 18, 18)
    .addComponent(txtSample, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
    .addComponent(txtFaculty, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
    .addComponent(txtName, javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(txtCity, javax.swing.GroupLayout.Alignment.TRAILING))))
    .addContainerGap(75, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(46, 46, 46)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jLabel1)
    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jLabel2)
    .addComponent(txtFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jLabel3)
    .addComponent(txtCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jButton1)
    .addComponent(txtSample, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addContainerGap(131, Short.MAX_VALUE))
    );
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    ConnectionClass cc = new ConnectionClass();
    if(cc.insertData(txtName.getText(),txtFaculty.getT ext(),txtCity.getText()))
    {
    System.out.print("Data is saved into database.");
    txtSample.setText("Data is saved.");
    txtName.setText("");
    txtFaculty.setText("");
    txtCity.setText("");
    }else System.out.print("Sorry, data is not saved.");

    }


    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField txtCity;
    private javax.swing.JTextField txtFaculty;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtSample;
    // End of variables declaration
    }


    ------------------------------
    connection class for my connection

    package com.in;

    import java.sql.*;
    import javax.swing.*;

    public class ConnectionClass
    {
    private Connection conn = null;

    public boolean createConnection()
    {
    try{
    Class.forName("org.postgresql.Driver"); //path to get the driver class
    conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/mydb2","postgres", "password");
    return true;
    }
    catch(Exception e)
    {
    JOptionPane.showMessageDialog(null, e);
    return false;
    }
    }
    public boolean insertData(String n, String f, String c)
    {
    if(conn == null)
    {
    if(!createConnection())
    {
    System.out.println("Connection Error");
    return false;
    }
    }

    PreparedStatement pstmt = null;
    String sql =("insert into student (name,faculty,city) values (?,?,?)") ;
    try
    {
    conn.setAutoCommit(false);
    pstmt = conn.prepareStatement(sql);
    pstmt.setString(1, n);
    pstmt.setString(2, f);
    pstmt.setString(3, c);
    if(pstmt.executeUpdate()==1)
    {
    conn.commit();
    return true;
    }
    else return false;
    }catch(SQLException sqle)
    {
    sqle.printStackTrace();
    }
    return false;
    }
    }

  6. #6
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: applets problems

    In Windows Control Panel there is a Java item. Open that, and find the "show the console" setting. Make sure you have the console open when you test this. This is where the stacktraces are.
    gghgc likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  7. #7
    gghgc is offline Member
    Join Date
    May 2014
    Posts
    9
    Rep Power
    0

    Default Re: applets problems



    sir.. i already did that.. is it possible to run postgresql database in browser? i really dont have any errors. but still the data are not storing in my database.

  8. #8
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: applets problems

    Quote Originally Posted by gghgc View Post
    is it possible to run postgresql database in browser?
    Do you really understand what you're asking here?

    How are you testing this? Do you have a webserver you are getting the applet from, or is it a local HTML page that you open via the filesystem? Applets cannot connect to any place else than the server they are loaded from. I don't know what happens when you "start" you applet via an HTML page on the local filesystem. Chances are you cannot connect to anything.

    Is the applet signed? Java Applets are pretty anal about permissions, for good reasons obviously, especially since the last update.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  9. #9
    gghgc is offline Member
    Join Date
    May 2014
    Posts
    9
    Rep Power
    0

    Default Re: applets problems

    https://www.youtube.com/watch?v=L7mm7ffp3FE

    sir i just followed the video tutorial there.. but instead of mysql i used postgresql.. i'd used apache tomcat 8.0.3.0 for webserver. and java ee version = java ee 7 for web. thank you.

Similar Threads

  1. Problems with applets
    By towmtdj in forum New To Java
    Replies: 10
    Last Post: 03-08-2013, 05:20 PM
  2. InputStream/Jar Problems/File IO Problems
    By rdjava in forum Advanced Java
    Replies: 31
    Last Post: 01-17-2011, 11:12 AM
  3. Problems viewing applets
    By teamvarsity87 in forum Java Applets
    Replies: 5
    Last Post: 02-24-2009, 01:58 AM
  4. problems with applet session between to two applets
    By elizabeth in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 03:23 PM
  5. Problems to show images in applets
    By Felissa in forum Java Applets
    Replies: 1
    Last Post: 07-06-2007, 09:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •