Display rows affected data from MySQL statement??

Hi,
Im trying to get the return data from a MySQL database, such as the ROWS AFFECTED into after an INSERT sql command.
Could anyone help me? I mean I know its easy in PHP to use the "mysql_affected_rows" command, but how do you do this in Java?
Many thanks!
Seb

executeUpdate will return the affected row count for insert, update, and delete statements. Is that what you're after?

Similar Messages

  • How to display data from mySQL database as a graph?

    I am working in DW, is there any function to insert graphs from recordset?

    My webpage is in php, don't tell me i have to work in coldfusion in order to display my data from mySQL graphically.
    Look at this link: http://www.adobe.com/devnet/coldfusion/articles/basic_chart.html

  • Problem while opening data from mysql  in Excel

    Hi friends
    when i try to download data from MySQL to excel sheet I am getting error of
    This file is not in a recognizable format.
    . If you know the file is from another program which is incompatible with Microsoft Office Excel,click Cancel then open this file in its original application.If you want to open the file later in Microsoft Office Excel,save it in a format that is compatible,such as text format.
    etc
    Code is
    Class.forName("org.gjt.mm.mysql.Driver");
    Connection conn = DriverManager.getConnection("xxxxxx");
    Statement st = conn.createStatement();
    StringBuffer sb = new StringBuffer();
    sb.append("SAP#" + "\t");
    sb.append("x-plant status" + "\t");
    sb.append("Total Amount" +"\t");
    sb.append(">90 days" + "\t");
    sb.append("\n");
    try
    String query="select * from temp_Xplant";
    ResultSet rs = st.executeQuery(query);
    while(rs.next()){
    sb.append(rs.getString("sapNo") + "\t");
    sb.append(rs.getString("status")+ "\t");
    sb.append(rs.getString("amt") + "\t");
    sb.append(rs.getString("days") + "\t");
    sb.append("\n");
    conn.close();
    st.close();
    catch (Exception e)
    out.println("error");
    conn.close();
    st.close();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=\"test.XLS\"");
    I can open them after clicking OK, but before that it is showing the above error message
    Thank you
    Edited by: priyap on Apr 3, 2008 4:54 AM

    hi,
    there are some specific restrictions in downloading data in alv.
    i.e you cannot have morethan 1024 characters that can be downloaded in single row.
    so change your report columns accordingly.

  • Unable to connect to the server to pull data from mysql

    Hello,
    I am novice working with Flash Builder 4 and I just created a test application which runs well in my computer pulling data from Mysql using PHP and populating a datagrid. But when I transfered it to the my hosting provider failed. I have been doing some modifications to the gateway.php and amf.config.ini to solve some of the issues. Now the application try to run but doesn't populate the data in the datagrid. I included a tracking point in my data service file to read the connections variables, but they come up in blank. I highly appreciate any help. Here are my gateway.php, amf.config.ini and the data service.
    gateway.php
    <?php
    ini_set("display_errors", 1);
    $dir = dirname(__FILE__);
    $webroot = $_SERVER['DOCUMENT_ROOT'];
    $configfile = "$dir/amf_config.ini";
    $fp = fopen("tracking.txt", "a");
    fwrite($fp, "1-config file " . $configfile . "\r\n");
    //default zend install directory
    $zenddir = $webroot. '/ZendFramework/library';
    //-$zenddir = $webroot;
    fwrite($fp, "2-default zendir" . $zenddir . "\r\n");
    //Load ini file and locate zend directory
    if(file_exists($configfile)) {
         $arr=parse_ini_file($configfile,true);
         if(isset($arr['zend']['webroot'])){
              $webroot = $arr['zend']['webroot'];
              $zenddir = $webroot. '/ZendFramework/library';
         if(isset($arr['zend']['zend_path'])){
              $zenddir = $arr['zend']['zend_path'];
    fwrite($fp, "3-after zendir" . $zenddir . "\r\n");
    // Setup include path
    //add zend directory to include path
    set_include_path(get_include_path().PATH_SEPARATOR.$zenddir);
    // Initialize Zend Framework loader
    require_once 'Zend/Loader/Autoloader.php';
    //-require_once 'Autoloader.php';
    Zend_Loader_Autoloader::getInstance();
    // Load configuration
    $default_config = new Zend_Config(array("production" => false), true);
    $default_config->merge(new Zend_Config_Ini($configfile, 'zendamf'));
    $default_config->setReadOnly();
    $amf = $default_config->amf;
    fwrite($fp, "4- configfile" . $dafault_config["production"] . "\r\n");
    // Store configuration in the registry
    Zend_Registry::set("amf-config", $amf);
    // Initialize AMF Server
    $server = new Zend_Amf_Server();
    $server->setProduction($amf->production);
    if(isset($amf->directories)) {
         $dirs = $amf->directories->toArray();
         foreach($dirs as $dir) {
             // get the first character of the path.
             // If it does not start with slash then it implies that the path is relative to webroot. Else it will be treated as absolute path
             $length = strlen($dir);
             $firstChar = $dir;
             if($length >= 1)
                  $firstChar = $dir[0];
             if($firstChar != "/"){
                  // if the directory is ./ path then we add the webroot only.
                  if($dir == "./"){                  
                       $server->addDirectory($webroot);
                  }else{
                       $tempPath = $webroot . "/" . $dir;
                        $server->addDirectory($tempPath);
              }else{
                      $server->addDirectory($dir);             
    fwrite($fp, "5-temp path" . $tempPath . "=>" . "\r\n");
    fwrite($fp, "******************************************" . "\r\n");
    // Initialize introspector for non-production
    if(!$amf->production) {
         $server->setClass('Zend_Amf_Adobe_Introspector', '', array("config" => $default_config, "server" => $server));
            $server->setClass('Zend_Amf_Adobe_DbInspector', '', array("config" => $default_config, "server" => $server));
    // Handle request
    echo $server->handle();
    ?>
    amf.config.ini
    [zend]
    ;set the absolute location path of webroot directory, example:
    ;Windows: C:\apache\www
    ;MAC/UNIX: /user/apache/www
    ;-webroot =c:/wamp/www/
    webroot = /home/frutiexp/public_html
    ;set the absolute location path of zend installation directory, example:
    ;Windows: C:\apache\PHPFrameworks\ZendFramework
    ;MAC/UNIX: /user/apache/PHPFrameworks/ZendFramework
    ;zend_path = /home/frutiexp/public_html/ZendFramework
    [zendamf]
    amf.production = true
    amf.directories[]=fb41/services
    ;amf.directories[]=./
    CoursesService.php
    <?php
    *  README for sample service
    *  This generated sample service contains functions that illustrate typical service operations.
    *  Use these functions as a starting point for creating your own service implementation. Modify the
    *  function signatures, references to the database, and implementation according to your needs.
    *  Delete the functions that you do not use.
    *  Save your changes and return to Flash Builder. In Flash Builder Data/Services View, refresh
    *  the service. Then drag service operations onto user interface components in Design View. For
    *  example, drag the getAllItems() operation onto a DataGrid.
    *  This code is for prototyping only.
    *  Authenticate the user prior to allowing them to call these methods. You can find more
    *  information at <link>
    class CoursesService {
         var $username = "myusername";
         var $password = "mypassword"
         var $server = "localhost";
         var $port = "3306";
         var $databasename = "frutiexp_trainsur";
         var $tablename = "courses";
         var $connection;
          * The constructor initializes the connection to database. Everytime a request is
          * received by Zend AMF, an instance of the service class is created and then the
          * requested method is invoked.
         public function __construct() {
                $this->connection = mysqli_connect(
                                              $this->server, 
                                              $this->username, 
                                              $this->password,
                                              $this->databasename,
                                              $this->port
    $fp = fopen("./tracking.txt", "a");
    fwrite($fp, "1-service".  $databasename . " " . $username . "\r\n");
    fclose($fp);
              $this->throwExceptionOnError($this->connection);
          * Returns all the rows from the table.
          * Add authroization or any logical checks for secure access to your data
          * @return array
         public function getAllCourses() {
              $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename");         
              $this->throwExceptionOnError();
              mysqli_stmt_execute($stmt);
              $this->throwExceptionOnError();
              $rows = array();
              mysqli_stmt_bind_result($stmt, $row->cou_id, $row->cou_title, $row->cou_overview, $row->cou_objectives);
             while (mysqli_stmt_fetch($stmt)) {
               $rows[] = $row;
               $row = new stdClass();
               mysqli_stmt_bind_result($stmt, $row->cou_id, $row->cou_title, $row->cou_overview, $row->cou_objectives);
              mysqli_stmt_free_result($stmt);
             mysqli_close($this->connection);
             return $rows;
          * Returns the item corresponding to the value specified for the primary key.
          * Add authroization or any logical checks for secure access to your data
          * @return stdClass

    Hello Jdesko,
    Thank you for you prompt response. Yes, I have changed the connections variables in my dataservice ( I didn't post real values). You are right, after all I didn't make changes on the gateway.php except to add some tracking points. The one that I changed is the amf.config,ini. The application runs without any error exceptions, but don't populate the datagrid. According with the tracing is stoping just when establishing the connection to the database. Please let me know if you have any other clue. thanks

  • Getting data from MySQL

    I'm a web developer that is familiar with PHP and MySQL. I
    just started working with a guy who has created a site in Flash for
    a client, and I've created the backend in PHP. It was understood
    that all I'd have to do would be to PUT information into the
    database and he'd pull it out on the site. Things have changed and
    I've been asked to pull the data down for him.
    I've Googled to find out that it's possible to get data from
    MySQL into Flash via a textfile formated as such: 'myVar=[data]'. I
    don't know the specifics, but I can figure that all out. However, I
    have two particular questions regarding the data:
    1.) How does Flash handle HTML formatting? The CMS I've
    written allows an administrator to input plain HTML and I store
    that in the database; how will that translate into Flash? Does
    Flash have an HTML parser? I've been having trouble filtering
    through searches on Google about using HTML to put Flash on a page
    instead of Flash parsing HTML. I read on another forum that Flash
    has an HTML 1.0 parser, but the post was dated August 2003.
    2.) I've also been storing images as BLOBs in MySQL. How do
    I go about pulling these images out? Of the tutorials I've found on
    Google, all I can hit with my searches are scenarios in which
    people store image
    paths in the database, and output them in the same textfile,
    'myImage=/images/image.jpg' etc.
    [url=http://forums.devarticles.com/web-development-40/flash-mysql-longblobs-9659.html]Thi s
    unanswered forum post off-site[/url], is similar to what I'm trying
    to do, but I'd need to display many images in a flash movie and I
    don't think passing them via src would work.
    I'm not necessarily asking for complete solutions for these
    problems, I just need to be pointed in the correct direction, maybe
    a function or a document I'm missing.

    quote:
    Originally posted by:
    MotionMaker
    1. Flash TextFields can handle a limited amount of HTML:
    Supported
    HTML tags. The .html property is enables HTML rendering and
    .htmlText property for asssigning the HTML.
    Those tags would probably be fine. We're not trying to do
    anything fancy.
    quote:
    2. Your PHP scripts cannot send back HTML. They can send back
    data either in URL Encoded format or XML. That means your script is
    only echoing data. The HTML can be stored in data such as a URL
    variable or in CDATA node of XML.
    Ex for URLVars: echo theHtml=<p>This
    is<b>bold</b></p>&var2=1234&var3=true;
    Ok, that's what I thought.
    quote:
    3. You will need your PHP script to create a temporary jpg
    file on the server and send to Flash the name of the file. Then you
    use either MovieClip.loadMovie or MovieClipLoader to fetch the jpg
    on the Flash side. There should be links on the web for the PHP
    part handling the filenaming and the garbage collection.
    Uhg, that's what I also thought, and was afraid of. You told
    me everything I need to know I think. Thank you.

  • How to get the data from mysql database which is being accessed by a PHP application and process the data locally in adobe air application and finally commit the changes back in to mysql database through the PHP application.

    How to get the data from mysql database which is being accessed by a PHP application and process the data locally in adobe air application and finally commit the changes back in to mysql database through the PHP application.

    If the data is on a remote server (for example, PHP running on a web server, talking to a MySQL server) then you do this in an AIR application the same way you would do it with any Flex application (or ajax application, if you're building your AIR app in HTML/JS).
    That's a broad answer, but in fact there are lots of ways to communicate between Flex and PHP. The most common and best in most cases is to use AMFPHP (http://amfphp.org/) or the new ZEND AMF support in the Zend Framework.
    This page is a good starting point for learning about Flex and PHP communication:
    http://www.adobe.com/devnet/flex/flex_php.html
    Also, in Flash Builder 4 they've added a lot of remote-data-connection functionality, including a lot that's designed for PHP. Take a look at the Flash Builder 4 public beta for more on that: http://labs.adobe.com/technologies/flashbuilder4/

  • How to fetch data from Mysql with SSL.

    I am using jdk1.5 and mysql 5.0.
    How to fetch data from Mysql with SSL
    I am using url = jdbc:mysql://localhost/database?useSSL=true&requireSSL=true.
    It shows error. how to fetch

    I have created certificate in mysql and checked in mysql.
    mysql>\s
    SSL: Cipher in use is DHE-RSA-AES256-SHA
    but through ssl how to fetch data in java.

  • Import data from mySQL into flash?

    I am new t this and therefore do not know if it can be done, but I want to import certain data from mySQL into a flash project. I know how to do this in PHP but not in action script. Help Please!

    You can use the data -> connect to php in FlashBuilder and generate a php sample file from your mysql db and use that as the service in your flex project.
    Check out http://sujitreddyg.wordpress.com/2009/06/01/building-flex-application-for-a-php-class-usin g-flash-builder-4/

  • Copy data from mysql to oracle database help?

    Im an sql newb and trying to understand how I can automatically copy data from one dtabase to another systems database on the same server.
    We have two differnt applications, but both share customer information, but one is on a win server, while the other is on oracle.
    Each time a customer contacts us via online chat (win server, mysql), we want to copy their entire chat transcript into our CRM's (oracle) customer account. So the folks that use the CRM can see the past chat histories. I hope this makes sense.
    Where can i look to get started on this?
    Thanks

    You could look at Heterogeneous Services (see the forum here Heterogeneous Connectivity but if you want to push data from mysql to oracle you might be better looking at it from the mssql side. I don't know what they offer.
    It might be simpler to do it at the client end. ie cut and paste from the online chat application into a new utility which inserts into the oracle database.
    Incidentally, this forum is specifically for the SQLDeveloper tool. You might get more general help in the "database - general" or "sql and pl/sql" forums

  • How to get data from MySQL into Analysis Services Tabular Model

    Hi,
    I have a problem with Analysis Services Tabular Model and MySQL ... I have to use several MySQL databases as a source of Tabuar Model ..
    Is there any way to get connection working from Tabular Model to retrieve data from MySQL database. I have a situation that in MySQL server there is several databases with same schema, one for each customer. I have planned to join these customer databases
    to one Tabular Model, create roles and users for each customer to query their data.
    What do I have to do to get this working ?
    Pasi

    Hi ,
      In Tabular model out of the box there is no direct connectors available for MySQL. Please see the list of supported Data Sources
    http://msdn.microsoft.com/en-us/library/gg492165.aspx
    But i think if you can establish a ODBC connectivity with data source to MYSQL , you can use the ODBC connection to retrieve the data from MySQL. Please try this and post the results here if it is possible or not.
    Best Regards Sorna

  • How can i display data from mysql (cant do it using netbeans)

    im confused with changing ResultSet-->List->Array;
    i already done displaying a data table from mysql but im lost on how to display mysql rows to ComboBoxes and JLists...
    im new here.
    how does the setModel() work?
    i hate this GUI stuff.. = (
    thanks...

    im new here.
    how does the setModel() work?
    i hate this GUI stuff.. = (You claim you have JDBC working already, if I understand your post correctly. So you're asking a question about GUIs in the JDBC forum. Not a good strategy. Try the Swing forum.

  • Can not get data from mySql

    I prepared a GUI user connection application in NebBeans 5.5 accessing mySql database in the company server. The application run very well in desktop.
    However, when I post it to the company server web, it gets nothing from the database.
    Can any one give advice???
    Thank you in advance.
    The following is my application
    import java.util.Vector;
    import java.awt.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public class UserConnection extends javax.swing.JFrame {
    //constants for database
    private final String userName = "labmanage";
    private final String password = "labmanage";
    private final String server = "jdbc:mysql://svr.corp.com/labmanage";
    private final String driver = "com.mysql.jdbc.Driver";
    private JDBCAdapter data = new JDBCAdapter(server, driver, userName, password);
    //variables
    private String user, pwd;
    private Vector<Vector<String>> userTable = new Vector<Vector<String>>();
    private Vector<String>colUserNames = new Vector<String>();
    * Creates new form UserConnection
    public UserConnection() {
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
    userLabel = new javax.swing.JLabel();
    pwdLabel = new javax.swing.JLabel();
    userTextField = new javax.swing.JTextField();
    passwordField = new javax.swing.JPasswordField();
    submitButton = new javax.swing.JButton();
    statusLabel = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    statusTextArea = new javax.swing.JTextArea();
    changePwdButton = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("User's Connection");
    setBackground(new java.awt.Color(153, 204, 255));
    setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    setFont(new java.awt.Font("aakar", 1, 12));
    userLabel.setText("User Name:");
    pwdLabel.setText("Password:");
    submitButton.setText("Submit");
    submitButton.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    submitButtonMouseClicked(evt);
    submitButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    submitButtonActionPerformed(evt);
    submitButton.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyTyped(java.awt.event.KeyEvent evt) {
    submitButtonKeyTyped(evt);
    statusLabel.setText("Status:");
    statusTextArea.setColumns(20);
    statusTextArea.setEditable(false);
    statusTextArea.setLineWrap(true);
    statusTextArea.setRows(3);
    statusTextArea.setText("Initial assigned password is \"dime\".");
    statusTextArea.setWrapStyleWord(true);
    jScrollPane1.setViewportView(statusTextArea);
    changePwdButton.setText("Change password");
    changePwdButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    changePwdButtonActionPerformed(evt);
    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .addContainerGap()
    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(userLabel)
    .add(pwdLabel)
    .add(statusLabel))
    .add(35, 35, 35)
    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .add(submitButton)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(changePwdButton))
    .add(passwordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
    .add(userTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE))
    .addContainerGap())
    layout.setVerticalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .addContainerGap()
    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(userLabel)
    .add(userTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(pwdLabel)
    .add(passwordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(statusLabel)
    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .add(15, 15, 15)
    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(submitButton)
    .add(changePwdButton))
    .addContainerGap(27, Short.MAX_VALUE))
    pack();
    }// </editor-fold>
    private void submitButtonKeyTyped(java.awt.event.KeyEvent evt) {                                     
    if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
    submitButton.doClick();
    submitButton.requestFocus();
    changePwdButton.requestFocus();
    private void changePwdButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
    String command = evt.getActionCommand();
    if(command.equals("Change password")) {
    passwordField.setText("");
    //Get connection to the changing password panel
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new ChangePassword().setVisible(true);
    private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
    // TODO add your handling code here:
    String command = evt.getActionCommand();
    if(command.equals("Submit")) {
    user = getUser();
    pwd = getPwd();
    data = new JDBCAdapter(server, driver, userName, password);
    data.executeQuery("SELECT * FROM USERTABLE");
    colUserNames = data.getColumnNames();
    userTable = data.getDataTable();
    if(colUserNames.elementAt(0).equals("")) {
    statusTextArea.setText("Can not connect to database");
    boolean checkUser = false;
    int i = 0;
    while(!checkUser && i<userTable.size()) {
    if(user.equalsIgnoreCase((String) userTable.elementAt(i).elementAt(0))) {
    //Find the user in database
    checkUser = true;
    //Check user's password
    if(pwd.equals((String)userTable.elementAt(i).elementAt(1))) {
    //Check for initial default password. The user is requested
    //to change his password
    if(pwd.equals((String) "dime")) {
    statusTextArea.setText("You are requested to change your " +
    "initial assigned password. Click 'Change password' please.");
    else {
    //Set UserConnection Panel to invisible
    setVisible(false);
    dispose();
    //Get connection to the table
    if(userTable.elementAt(i).elementAt(2).equals("0")) {
    //Get connection to non-editable table
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    PVRackReportNonEdit rackReport = new PVRackReportNonEdit();
    rackReport.createAndShowDialog();
    else {
    if(userTable.elementAt(i).elementAt(2).equals("1")) {
    //Get connection to editable table
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    PVRackReport rackReport = new PVRackReport(user);
    rackReport.createAndShowDialog();
    //PVRackReport rackReport = new PVRackReport();
    else statusTextArea.setText("You do not get approval for viewing data. " +
    "Please contact the administrator for details.");
    else {
    passwordField.setText("");
    statusTextArea.setText("Please enter corrected password or" +
    "the administrator for details.");
    i++;
    if(!checkUser) {
    passwordField.setText("");
    statusTextArea.setText("Not find such user's name." +
    "contact the admistrator for details.");
    private void submitButtonMouseClicked(java.awt.event.MouseEvent evt) {                                         
    // TODO add your handling code here:
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new UserConnection().setVisible(true);
    public String getUser() {
    return userTextField.getText();
    public String getPwd() {
    return passwordField.getText();
    // Variables declaration - do not modify
    private javax.swing.JButton changePwdButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPasswordField passwordField;
    private javax.swing.JLabel pwdLabel;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JTextArea statusTextArea;
    private javax.swing.JButton submitButton;
    private javax.swing.JLabel userLabel;
    private javax.swing.JTextField userTextField;
    // End of variables declaration
    Here is my JDBCAdapter
    package rackdemo2;
    * This is an adaptor which transforms the JDBC interface
    * to the PVRackTableDialogue
    import java.util.Vector;
    import java.sql.*;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.event.TableModelEvent;
    public class JDBCAdapter {
    Connection connection;
    Statement statement;
    ResultSet resultSet;
    Vector<String> columnNames = new Vector<String>();
    Vector<Vector<String>> rows = new Vector<Vector<String>>();
    ResultSetMetaData metaData;
    public JDBCAdapter(String url, String driverName,
    String user, String passwd) {
    try {
    Class.forName(driverName);
    connection = DriverManager.getConnection(url, user, passwd);
    statement = connection.createStatement();
    catch (ClassNotFoundException ex) {
    System.err.println("Cannot find the database driver classes.");
    System.err.println(ex);
    catch (SQLException ex) {
    System.err.println("Cannot connect to this database.");
    System.err.println(ex);
    public void executeQuery(String query) {
    if (connection == null || statement == null) {
    System.err.println("There is no database to execute the query.");
    return;
    try {
    resultSet = statement.executeQuery(query);
    metaData = resultSet.getMetaData();
    int numberOfColumns = metaData.getColumnCount();
    // Get the column names and cache them.
    // Then we can close the connection.
    for(int column = 0; column < numberOfColumns; column++) {
    columnNames.addElement(metaData.getColumnLabel(column+1));
    // Get all rows.
    while (resultSet.next()) {
    Vector<String> newRow = new Vector<String>();
    for (int i = 1; i <= columnNames.size(); i++) {
    String tempString = resultSet.getString(i);
    if(!tempString.equals("null")) {
    newRow.addElement(tempString);
    else {
    newRow.addElement("");
    rows.addElement(newRow);
    //Modify dataTable to add empty row to separate chassis
    if(numberOfColumns>1) {
    int nRow = rows.size();
    Vector<String> row = new Vector<String>();
    for(int i=0; i<numberOfColumns; i++){
    row.add("");
    if(nRow>0 || numberOfColumns>0) {
    //Adding blank row to separate chassis
    int i = 0;
    while(i<nRow) {
    if(!rows.elementAt(i).elementAt(0).equals("")) {
    if(i>0) {
    rows.add(i, row);
    i++;
    nRow = rows.size();
    i++;
    close();
    catch (SQLException ex) {
    System.err.println(ex);
    public void close() throws SQLException {
    resultSet.close();
    statement.close();
    connection.close();
    // MetaData
    public Vector<String> getColumnNames() {
    return columnNames;
    public Vector<Vector<String>> getDataTable() {
    return rows;
    public int getColumnCount() {
    return columnNames.size();
    // Data methods
    public int getRowCount() {
    return rows.size();
    }

    Thank you for your answer.
    I'm very new to mySql as server. When I was assigned
    to write the application, the administrator has set
    up mySql database in the company web server for my
    application. My program runs very when using my
    workplace desktop with java web start or with java
    web start in netbeans (all paths should be link to my
    desktop hard disk, i.e. users/application/). I can
    not run the application at home because I can not
    access to the company intranet server (for security
    purpose). The problem happens when I post the
    application in the company web page (I have to modify
    all paths in jnlp file to the company web address).
    The program then runs without exception except it
    seems that it gets no data from the database (for
    example, when I type my username, it returns that
    "There is no such user name. contact.." as what I
    code in the application for not correcting user name)
    It happens for not only using my company desktop but
    also for others.
    Please help me.
    Thank you in advance.And all this could have been answered yesterday, in your other thread, when I asked you "Is the DB configured to allow that user to connect to the DB from where that user is attempting to connect from?"
    Seeing as how you get that error, the obvious answer was, "No." At which point we could have continued.
    Configure the needed users into the DB, without forgetting to allow them access from the machines from which they are going to access from.
    Although, I agree with Rene, that you should set up a server of some sort, located on the same machine as the DB, for communicating with the DB.

  • How to display the updated data from db to user interface in sruts framewor

    A beginner in this area, I have been able to read a record from a
    MySQL database and populate in jsp form . Now, my goal is to
    allow the user to edit the contents of the form and then update the
    record in MySQL and then display the same in jsp. page
    The scenario in detail
    1)the data is fetched from db and displayed in non-editable format
    2)Next button is clicked
    3)Now in the same jsp page I view the same data from db in editable format
    4)The user is allowed to change the information
    5)Now update button is clicked
    6)the records are updated in the db -Finished doing till this step
    7)But the updated info in non - editable format to be displayed in jsp page is left pending.
    Here is my code for jsp,i want know how to write an action for this,tried doing the same in java and I'm successful.but what I need is how to fetch the updated information in the user interface.
    I've made both editable as well as non editable info in the same page with different actions.
    pl help me,I'm a newbie
    <%@ taglib uri="/WEB-INF/struts-bean" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-logic" prefix="logic" %>
    <%@ page language="java" %>
    <%@ page import="java.util.ArrayList,java.util.Iterator" %>
    <%@ page import="com.finocus.common.container.CustomerDetailsTest;" %>
    <html:html>
    <head>
         <title>CUSTOMER DISPLAY</title>
    </head>
    <body>
         <table width="100%" bgcolor="darkkhaki">
         <tr>
              <td><table width="100%" bgcolor="indigo">
                   <tr>
                        <td><font color="white">Display</font></td>
                        <td><font color="white">Update</font></td>
                        <td><font color="white">Verify</font></td>
                        <td><font color="white">Confirm</font></td>
                   </tr>
                   </table>
              </td>
         </tr>
    <%
              //Container for holding data
              ArrayList list = (ArrayList)session.getAttribute("CUSTOMERDETAILS");
              Iterator itr=list.iterator();
              while(itr.hasNext())
              CustomerDetailsTest cust = (CustomerDetailsTest) itr.next();
              System.out.println("testGetCustomerDetails()-successed. retrieved CustomerDetailsTest="+cust.toString());
    %>
    <%
              //Session for checking whether edit or non-edit mode
              String pageMode = (String)session.getAttribute("CUSTOMER_PAGE_MODE");
              session.removeAttribute("CUSTOMER_PAGE_MODE");
              if(null==pageMode)
                   pageMode = "EDIT";
              if(pageMode.equals("EDIT"))
                   //display data in the form
                   System.out.println("Editable mode");
    %>
              <html:form action="/nonedit">
                   <tr>
              <td><table width="100%" bgcolor="darkkhaki">
              <tr>
                        <td><b><bean:message key="label.id"/></b></td>
                        <td><font color="red"><%=cust.getCusId()%></font></td>
         </tr><br>
         <td>
                             <font color="brown" face="Courier New"><b>
                        <bean:message key="label.Company"/></b>
                        </td><br>
                        <tr>
                   <td><bean:message key="label.cname"/></td>
                   <td><font color="blue"><html:text property="name" value="<%=cust.getCname()%>"/></font></td>
                        <td><bean:message key="label.cphone"/></td>
                        <td><font color="blue"><html:text property="phone" value="<%=cust.getCphone()%>"/></font></td>
              </tr><br>
         <tr>
                   <td><bean:message key="label.caddr1"/></td>
                   <td><font color="blue"><html:text property="address1" value="<%=cust.getCaddress1()%>"/></font></td>
                        <td><bean:message key="label.cemail"/></td>
                        <td><font color="blue"><html:text property="email" value="<%=cust.getCemail()%>"/></font></td>
              </tr><br>
         <tr>
                   <td><bean:message key="label.caddr2"/></td>
                   <td><font color="blue"><html:text property="address2" value="<%=cust.getCaddress2()%>"/></font></td>
                        <td><bean:message key="label.cfax"/></td>
                        <td><font color="blue"><html:text property="fax" value="<%=cust.getCfax()%>"/></font></td>
              </tr><br>
         <tr>
                   <td><bean:message key="label.ccity"/></td>
                   <td><font color="blue"><html:text property="city" value="<%=cust.getCcity()%>"/></font></td>
                        <td><bean:message key="label.czip"/></td>
                        <td><font color="blue"><html:text property="zip" value="<%=cust.getZip()%>"/></font></td>
              </tr><br>
         <tr>
                   <td><b><bean:message key="label.cstate"/></b></td>
                   <td><font color="red"><html:text property="state" value="<%=cust.getCstate()%>"/></font></td>
         </tr><br>
         <td>
                             <font color="brown" face="Courier New"><b>
                        <bean:message key="label.Admin"/></b>
                        </td><br>
         <tr>
                   <td><b><bean:message key="label.AAname"/></b></td>
                   <td><font color="red"><html:text property="adminname" value="<%=cust.getAname()%>"/></font></td>
         </tr><br>
         <tr>
                   <td><b><bean:message key="label.AAemail"/></b></td>
                   <td><font color="red"><html:text property="adminemail" value="<%=cust.getAemail()%>"/></font></td>
         </tr><br>
         <tr>
                   <td><b><bean:message key="label.AAphone"/></b></td>
                   <td><font color="red"><html:text property="adminphone" value="<%=cust.getAphone()%>"/></font></td>
         </tr><br>
         <td>
                             <font color="brown" face="Courier New"><b>
                        <bean:message key="label.User"/></b>
                        </td><br>
         <tr>
                   <td><b><bean:message key="label.AUname"/></b></td>
                   <td><font color="red"><html:text property="adminusername" value="<%=cust.getUname()%>"/></font></td>
         </tr><br>
         <tr>
                   <td><b><bean:message key="label.AUemail"/></b></td>
                   <td><font color="red"><html:text property="adminuseremail" value="<%=cust.getUemail()%>"/></font></td>
         </tr><br>
              <tr align="center">
                        <td><html:cancel value="Cancel"/>
                        <html:submit value="Next"/></td>
              </tr>
              </html:form>
    <%               
              }else
                   //display data in the text
                   System.out.println("Non-Editable mode");
    %>
              <html:form action="/edit">
              <tr>
              <td><table width="100%" bgcolor="darkkhaki">
                   <tr>
                        <td><b><bean:message key="label.id"/></b></td>
                        <td><font color="red"><%=cust.getCusId()%></font></td>
                        <td><b><bean:message key="label.status"/></b></td>
                        <td><font color="red"><%=cust.getStatus() %></font></td>
         </tr><br>
         <td>
                             <font color="brown" face="Courier New"><b>
                        <bean:message key="label.Company"/></b>
                        </td><br>
                        <tr>
                   <td><bean:message key="label.cname"/></td>
                   <td><font color="blue"><%=cust.getCname()%></font></td>
                        <td><bean:message key="label.cphone"/></td>
                        <td><font color="blue"><%=cust.getCphone()%></font></td>
              </tr><br>
         <tr>
                   <td><bean:message key="label.caddr1"/></td>
                   <td><font color="blue"><%=cust.getCaddress1()%></font></td>
                        <td><bean:message key="label.cemail"/></td>
                        <td><font color="blue"><%=cust.getCemail()%></font></td>
              </tr><br>
         <tr>
                   <td><bean:message key="label.caddr2"/></td>
                   <td><font color="blue"><%=cust.getCaddress2()%></font></td>
                        <td><bean:message key="label.cfax"/></td>
                        <td><font color="blue"><%=cust.getCfax()%></font></td>
              </tr><br>
         <tr>
                   <td><bean:message key="label.ccity"/></td>
                   <td><font color="blue"><%=cust.getCcity()%></font></td>
                        <td><bean:message key="label.czip"/></td>
                        <td><font color="blue"><%=cust.getZip()%></font></td>
              </tr><br>
         <tr>
                   <td><b><bean:message key="label.cstate"/></b></td>
                   <td><font color="red"><%=cust.getCstate()%></font></td>
         </tr><br>
         <td>
                             <font color="brown" face="Courier New"><b>
                        <bean:message key="label.Admin"/></b>
                        </td><br>
         <tr>
                   <td><b><bean:message key="label.AAname"/></b></td>
                   <td><font color="red"><%=cust.getAname()%></font></td>
         </tr><br>
         <tr>
                   <td><b><bean:message key="label.AAemail"/></b></td>
                   <td><font color="red"><%=cust.getAemail()%></font></td>
         </tr><br>
         <tr>
                   <td><b><bean:message key="label.AAphone"/></b></td>
                   <td><font color="red"><%=cust.getAphone()%></font></td>
         </tr><br>
         <td>
                             <font color="brown" face="Courier New"><b>
                        <bean:message key="label.User"/></b>
                        </td><br>
         <tr>
                   <td><b><bean:message key="label.AUname"/></b></td>
                   <td><font color="red"><%=cust.getUname()%></font></td>
         </tr><br>
         <tr>
                   <td><b><bean:message key="label.AUemail"/></b></td>
                   <td><font color="red"><%=cust.getUemail()%></font></td>
         </tr><br>
         <tr align="center">
                        <td><html:submit value="Update"/></td>
              </tr>
              </html:form>
    <%
    %>
    <%
    %>
                   </table>
              </td>
              </tr>
         </table>
    </body>
    </html:html>

    u r using action classes. so after calling the insert method in Action Class to a dao... the next statement should be retrieve statement. so at the time of updating first it will get updated.. the next statement it will execute is retrieve and then set these details in VO or FORM and show it on JSP
    Message was edited by:
    leo_michael

  • How to display rows of data in JSP?

    Hi,
    I am learning Servlet and JSP. There is an exercise which requires us to access a database from a Servlet and display the retrieved data in a JSP.
    Now I am ok with the database connection. So how to display the data using some kind of loop?
    Regards

    They're called ResultSets and they are returned when you execute a query from a Statement. The next() method will tell you whether or not you have another row of data to read.

  • Retrieve Data From MySQL

    Hi all,
    My scenario is :
    I have some events and dates in the database
    Ex:
    Event    Date
    event1   date1
    event2   date5
    event3   date7I want to display the events in a table, according to the dates.
    date1     date2      date3     date4     date5      date6     date7
    event1                                           event5                  event7i tried to use ResultSet method,, but i could not acheive it..
    I hope my question is understandable..
    I would be thankful to you guys, if u help me to solve the problem..
    Edited by: frenchiee on Aug 6, 2008 10:08 AM

    i have one more error but in different line..!! can u please help me out?
    try {
              String connectionURL = "jdbc:mysql://localhost:3234/";
              Connection connection = null;
              Statement statement = null;
              ResultSet rs = null;
              Class.forName("com.mysql.jdbc.Driver").newInstance();
              connection = DriverManager.getConnection(connectionURL, "root", "***");
              statement = connection.createStatement();
              String nameQuery = "select DISTINCT InstName from calendar  where (calendar.Date BETWEEN '2008-07-28' AND '2008-08-03')";
              rs= statement.executeQuery(nameQuery);
              String str ="";
    %>
              <table cellpadding="1" border="1"   cellspacing="1">
        <%      while (rs.next()) { %>
                      <tr >
                           <td width= "206" >
                           <% str = rs.getString(1); %> <%=rs.getString(1)%>
                           </td>
           <%
              String connection1URL = "jdbc:mysql://localhost:3234/";
               Connection connection1 = null;
              Statement statement1 = null;
                ResultSet es = null;
              Class.forName("com.mysql.jdbc.Driver").newInstance();
              connection1 = DriverManager.getConnection(connection1URL, "root", "*******");
              statement1 = connection1.createStatement();
                 String eventQuery = "select Event, Date from calendar where (InstName = '" + str +  "'AND(calendar.Date BETWEEN '2008-07-28' AND '2008-08-03'))";
                 System.out.println("eventQuery"+eventQuery);
                 es = statement1.executeQuery(eventQuery);
                 Calendar cal1 = Calendar.getInstance();
                   cal1.set(Calendar.YEAR, 2008);
                   cal1.set(Calendar.MONTH, Calendar.AUGUST);
                   cal1.set(Calendar.DATE, 4);
                   cal1.set(Calendar.HOUR, 0);
                   cal1.set(Calendar.MINUTE, 0);
                   cal1.set(Calendar.SECOND, 0);
                   cal1.set(Calendar.MILLISECOND, 0);
                   long millis = cal1.getTime().getTime();
                   java.sql.Date d = new java.sql.Date(millis);
                 Calendar cal2 = Calendar.getInstance();
                   cal2.set(Calendar.YEAR, 2008);
                   cal2.set(Calendar.MONTH, Calendar.AUGUST);
                   cal2.set(Calendar.DATE, 4);
                   cal2.set(Calendar.HOUR, 0);
                   cal2.set(Calendar.MINUTE, 0);
                   cal2.set(Calendar.SECOND, 0);
                   cal2.set(Calendar.MILLISECOND, 0);
                   long millis2 = cal1.getTime().getTime();
                   java.sql.Date d2 = new java.sql.Date(millis2);
                 cal2.add(Calendar.DAY_OF_YEAR, 6);
                 long millis3 = cal2.getTime().getTime();     
                 java.sql.Date d3 = new java.sql.Date(millis3);
                      while (es.next()){
                           while(!d3.equals(%> <%=es.getDate(2)%> <%)){ %>
                                       <td>   </td>
                                <%     cal1.add(Calendar.DAY_OF_YEAR, 1);
                                     long millis1 = cal1.getTime().getTime();     
                                     java.sql.Date d1 = new java.sql.Date(millis1);
                                    } %>
                                <td><%= es.getString(1) %></td>
                        <%
                             } %>
                   </tr>
             <%      }     
                       rs.close();
                  statement.close();
                  connection.close(); %>
        </table>
         <% } catch (Exception ex){} %>  // here it shows an error " syntax error on token ",", delete this token
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for