Simple mysql query Check in database

Basically I'm just trying to chekc whether the user exists on the database.
Mysql Table has - name user, pass...
My servlet is issuing query - String sql = "SELECT * FROM users WHERE username'"+user'";
ResultSet rs = stmt.executeQuery(sql);
Question - how do i check if the query's result.
Simple user authentication via database. Sorry but im new to Java
Pls help

Mysql Table has - name user, pass...
My servlet is issuing query - String sql = "SELECT *
FROM users WHERE username'"+user'";Does this query work?
ResultSet rs = stmt.executeQuery(sql);
Question - how do i check if the query's result.
Simple user authentication via database. Sorry but
im new to JavaFor the simplest authentication, I would use
SELECT count(*) FROM users WHERE username = '<user>' and password = '<password>'
To read through the resultset for this query:
if(rs.next() && rs.getInt(1) > 0) {
    System.out.println("User validated");
} else {
    System.out.println("User credentials do not match");
}What you need is http://java.sun.com/docs/books/tutorial/jdbc/

Similar Messages

  • Simple MySQL Query issue

    Hi. I have Dreamweaver CS3. My website connects to a MySQL
    database. Everything has worked properly up until now.
    I desire to buld a page that will display all records that
    have been populated in one of the tables in my database. I have 4
    tables in the database. When I attempt to create a recordset to
    access the desired data, and then hit the test button in the
    recordset query dialog box, I receive:
    "No Recordset was returned."
    There are 236 rows of data in the table. The query that I
    create in the dialog box is:
    SELECT *
    FROM visitors
    where visitors is the name of the table. If I replace
    "visitors" with the name of any of the other three tables, I get a
    valid recordset returned. These other tables have no more than 7
    records in them. If I modify the original select statement to read:
    SELECT *
    FROM visitors
    WHERE visitors.contactnum = 10
    I get a valid one-record recordset returned. So it appears to
    be connecting properly to the database. It's just that for some
    reason, when trying to get all records from the table, it doesn't.
    Is there a count limit to getting a valid recordset returned? I'm a
    relative newbie, so I don't really know where to debug any more
    than I've already done.
    Thanks. macnmotion.

    Well even though the "test" functionality says no records
    returned, the recordset actually contains the records and works as
    expected in my web page. Not sure if this is a DW bug or if I'm
    doing something wrong, but anyway it ultimately works as I
    need.

  • [SLVD] MySQL Query Browser (1.2.12) hangs when changing schma/database

    After a rather big upgrade yesterday (see paste below) I have got a problem with MySQL query browser which is found in package mysql-gui-tools. Everything else seems to be okay, but after upgrading mysql-gui-tools from 5.0r12-3 to 5.0r14-1 (..and now, after another update, its at 5.0r14-2) it is no longer able to refresh schema/databases. Every time I try to change/refresh schema in the schema menu to the right the program hangs and I have to kill it. A refresh icon appears as normal to the left of the schema I'm trying to refresh, but that icon too has frozen. I am however able to execute normal SELECT queries etc if I write the full "path" to the table in the SQL query, but when I try a USE query the same thing happens.
    I have done some searching on the Internet about this and found this thread to be interesting. Too bad it's from July 2007..
    I tried to downgrade to the old version of query browser, but then I got this problem:
    /usr/bin/mysql-query-browser-bin: error while loading shared libraries: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory
    ..So I guess theres a dependency problem here with the old version.
    Has anyone else got any problem with the MySQL Query Browser after upgrade or has any ideas for a solution?
    Log from pacman:
    [2009-04-12 13:52] synchronizing package lists
    [2009-04-12 13:52] starting full system upgrade
    [2009-04-12 13:55] upgraded xf86-input-evdev (2.1.2-1 -> 2.2.1-1)
    [2009-04-12 13:55] upgraded xorg-server (1.5.3-5 -> 1.6.0-3)
    [2009-04-12 13:56] synchronizing package lists
    [2009-04-12 13:56] starting full system upgrade
    [2009-04-12 13:56] upgraded glib2 (2.20.0-1 -> 2.20.1-1)
    [2009-04-12 13:56] upgraded libcap (1.10-2 -> 2.16-3)
    [2009-04-12 13:56] upgraded avahi (0.6.24-1 -> 0.6.24-3)
    [2009-04-12 13:56] upgraded cdrkit (1.1.9-1 -> 1.1.9-2)
    [2009-04-12 13:56]
    [2009-04-12 13:56] >>> Deluge's daemon is running with the "deluge" user. The default download directory is /srv/deluge/
    [2009-04-12 13:56]
    [2009-04-12 13:56] upgraded deluge (1.1.5-1 -> 1.1.6-3)
    [2009-04-12 13:56] upgraded jack-audio-connection-kit (0.109.2-2 -> 0.116.2-1)
    [2009-04-12 13:56] upgraded gstreamer0.10-bad-plugins (0.10.11-2 -> 0.10.11-3)
    [2009-04-12 13:56] upgraded hdparm (9.12-1 -> 9.14-1)
    [2009-04-12 13:56] upgraded iptables (1.4.2-1 -> 1.4.3.1-1)
    [2009-04-12 13:56] upgraded kbproto (1.0.3-1 -> 1.0.3-2)
    [2009-04-12 13:57] upgraded kdelibs (4.2.2-3 -> 4.2.2-4)
    [2009-04-12 13:57] upgraded kernel26-firmware (2.6.28-1 -> 2.6.29-1)
    [2009-04-12 13:59] >>> Updating module dependencies. Please wait ...
    [2009-04-12 13:59] >>> MKINITCPIO SETUP
    [2009-04-12 13:59] >>> ----------------
    [2009-04-12 13:59] >>> If you use LVM2, Encrypted root or software RAID,
    [2009-04-12 13:59] >>> Ensure you enable support in /etc/mkinitcpio.conf .
    [2009-04-12 13:59] >>> More information about mkinitcpio setup can be found here:
    [2009-04-12 13:59] >>> http://wiki.archlinux.org/index.php/Mkinitcpio
    [2009-04-12 13:59]
    [2009-04-12 13:59] >>> Generating initial ramdisk, using mkinitcpio. Please wait...
    [2009-04-12 13:59] ==> Building image "default"
    [2009-04-12 13:59] ==> Running command: /sbin/mkinitcpio -k 2.6.29-ARCH -c /etc/mkinitcpio.conf -g /boot/kernel26.img
    [2009-04-12 13:59] :: Begin dry run
    [2009-04-12 13:59] :: Parsing hook [base]
    [2009-04-12 13:59] :: Parsing hook [udev]
    [2009-04-12 13:59] :: Parsing hook [autodetect]
    [2009-04-12 13:59] :: Parsing hook [pata]
    [2009-04-12 13:59] :: Parsing hook [scsi]
    [2009-04-12 13:59] :: Parsing hook [sata]
    [2009-04-12 13:59] :: Parsing hook [usbinput]
    [2009-04-12 13:59] :: Parsing hook [keymap]
    [2009-04-12 13:59] :: Parsing hook [filesystems]
    [2009-04-12 13:59] :: Generating module dependencies
    [2009-04-12 13:59] :: Generating image '/boot/kernel26.img'...SUCCESS
    [2009-04-12 13:59] ==> SUCCESS
    [2009-04-12 13:59] ==> Building image "fallback"
    [2009-04-12 13:59] ==> Running command: /sbin/mkinitcpio -k 2.6.29-ARCH -c /etc/mkinitcpio.conf -g /boot/kernel26-fallback.img -S autodetect
    [2009-04-12 13:59] :: Begin dry run
    [2009-04-12 13:59] :: Parsing hook [base]
    [2009-04-12 13:59] :: Parsing hook [udev]
    [2009-04-12 13:59] :: Parsing hook [pata]
    [2009-04-12 13:59] :: Parsing hook [scsi]
    [2009-04-12 13:59] :: Parsing hook [sata]
    [2009-04-12 13:59] :: Parsing hook [usbinput]
    [2009-04-12 13:59] :: Parsing hook [keymap]
    [2009-04-12 13:59] :: Parsing hook [filesystems]
    [2009-04-12 13:59] :: Generating module dependencies
    [2009-04-12 14:00] :: Generating image '/boot/kernel26-fallback.img'...SUCCESS
    [2009-04-12 14:00] ==> SUCCESS
    [2009-04-12 14:00] upgraded kernel26 (2.6.28.8-1 -> 2.6.29.1-3)
    [2009-04-12 14:00] upgraded klibc-udev (140-1 -> 141-1)
    [2009-04-12 14:00] upgraded libavc1394 (0.5.3-1 -> 0.5.3-2)
    [2009-04-12 14:00] upgraded libcddb (1.3.0-3 -> 1.3.2-1)
    [2009-04-12 14:00] upgraded libdatrie (0.1.2-1 -> 0.2.1-1)
    [2009-04-12 14:00] upgraded libdrm (2.3.1-3 -> 2.4.9-1)
    [2009-04-12 14:00] upgraded libdvdread (0.9.7-1 -> 0.9.7-2)
    [2009-04-12 14:00] upgraded libfontenc (1.0.4-1 -> 1.0.4-2)
    [2009-04-12 14:00] upgraded libid3tag (0.15.1b-2 -> 0.15.1b-3)
    [2009-04-12 14:00] upgraded libmatroska (0.8.1-1 -> 0.8.1-2)
    [2009-04-12 14:00] upgraded libmpd (0.16.1-1 -> 0.18.0-1)
    [2009-04-12 14:00] upgraded libmysqlclient (5.0.77-1 -> 5.1.33-1)
    [2009-04-12 14:00] upgraded libogg (1.1.3-1 -> 1.1.3-2)
    [2009-04-12 14:00] upgraded libsamplerate (0.1.6-1 -> 0.1.7-1)
    [2009-04-12 14:00] upgraded libthai (0.1.9-1 -> 0.1.11-1)
    [2009-04-12 14:00] upgraded libx11 (1.2-1 -> 1.2.1-1)
    [2009-04-12 14:00] installed libftdi (0.15-1)
    [2009-04-12 14:00] upgraded lirc-utils (0.8.4-1 -> 0.8.5pre2-1)
    [2009-04-12 14:00] upgraded m4 (1.4.12-1 -> 1.4.13-1)
    [2009-04-12 14:00] upgraded man-db (2.5.4-2 -> 2.5.5-1)
    [2009-04-12 14:00] upgraded man-pages (3.19-1 -> 3.20-1)
    [2009-04-12 14:00] upgraded nvidia-utils (180.29-3 -> 180.44-1)
    [2009-04-12 14:00] installed dri2proto (1.99.3-1)
    [2009-04-12 14:01] upgraded mesa (7.2-1 -> 7.4-1)
    [2009-04-12 14:01] upgraded mpfr (2.3.2-2 -> 2.4.1-1)
    [2009-04-12 14:01] upgraded mpg123 (1.7.1-4 -> 1.7.2-1)
    [2009-04-12 14:01] upgraded mysql-clients (5.0.77-1 -> 5.1.33-1)
    [2009-04-12 14:01] upgraded mysql (5.0.77-3 -> 5.1.33-1)
    [2009-04-12 14:01] upgraded mysql-gui-tools (5.0r12-3 -> 5.0r14-1)
    [2009-04-12 14:01] In order to use the new nvidia module, exit Xserver and unload it manually.
    [2009-04-12 14:01] upgraded nvidia (180.29-3 -> 180.44-1)
    [2009-04-12 14:01] warning: /etc/pacman.d/mirrorlist installed as /etc/pacman.d/mirrorlist.pacnew
    [2009-04-12 14:01] upgraded pacman-mirrorlist (20090108-1 -> 20090405-1)
    [2009-04-12 14:01] upgraded pango (1.24.0-1 -> 1.24.0-2)
    [2009-04-12 14:01] upgraded php (5.2.9-2 -> 5.2.9-3)
    [2009-04-12 14:01] upgraded pm-utils (1.2.4-3 -> 1.2.5-1)
    [2009-04-12 14:01] installed perl-xyne-common (0.01-5)
    [2009-04-12 14:01] installed perl-html-tagset (3.20-1)
    [2009-04-12 14:01] installed perl-html-parser (3.60-1)
    [2009-04-12 14:01] installed perl-libwww (5.825-1)
    [2009-04-12 14:01] installed perl-xyne-arch (0.03-5)
    [2009-04-12 14:01] ######################
    [2009-04-12 14:01] ## IMPORTANT NOTICE ##
    [2009-04-12 14:01] ######################
    [2009-04-12 14:01] Powerpill options and configuration file syntax have changed with
    [2009-04-12 14:01] version 16.0. Please remove old configuration files and use the
    [2009-04-12 14:01] default configuration file at /etc/powerpill.conf as a template for new
    [2009-04-12 14:01] ones. Please see the man page for information on the command-line options.
    [2009-04-12 14:01] upgraded powerpill (15.12-1 -> 16.0-5)
    [2009-04-12 14:01] upgraded python-numpy (1.2.1-4 -> 1.3.0-1)
    [2009-04-12 14:02] upgraded qt (4.5.0-3 -> 4.5.0-4)
    [2009-04-12 14:02] upgraded qt3 (3.3.8-9 -> 3.3.8-10)
    [2009-04-12 14:02] upgraded redland (1.0.8-1 -> 1.0.8-3)
    [2009-04-12 14:02] upgraded tdb (3.3.1-1 -> 3.3.3-1)
    [2009-04-12 14:02] upgraded smbclient (3.3.1-1 -> 3.3.3-1)
    [2009-04-12 14:02] upgraded subversion (1.6.0-2 -> 1.6.1-2)
    [2009-04-12 14:02] upgraded syslog-ng (3.0.1-4 -> 3.0.1-6)
    [2009-04-12 14:02] upgraded tzdata (2009d-1 -> 2009e-1)
    [2009-04-12 14:02] upgraded udev (140-2 -> 141-1)
    [2009-04-12 14:02] upgraded xf86-input-keyboard (1.3.2-1 -> 1.3.2-2)
    [2009-04-12 14:02] upgraded xf86-input-mouse (1.3.0-1 -> 1.4.0-2)
    [2009-04-12 14:02] upgraded xf86-video-vesa (2.1.0-1 -> 2.2.0-1)
    [2009-04-12 14:02] upgraded xfce4-mpc-plugin (0.3.3-2 -> 0.3.3-3)
    [2009-04-12 14:02] upgraded xorg-server-utils (7.4-3 -> 7.4-4)
    [2009-04-12 14:02] upgraded xorg-utils (7.4-2 -> 7.4-3)
    Last edited by siaco (2009-04-14 21:42:10)

    I found the error on this. In the current PGKBUILD found in AUR, the patch mysql-gui-tools.chema_change_freeze_bug.patch is no longer applied.
    I downloaded all related files to this package and built it myself now, with some changes to PGKBUILD and the mysql-gui-tools.chema_change_freeze_bug.patch. It works again :-)
    New PGKBUILD:
    # $Id: PKGBUILD,v 1.14 2009/04/12 11:52:45 dsa Exp $
    # Maintainer: Douglas Soares de Andrade <[email protected]>
    # Contributor: Vinay S Shastry <[email protected]>
    pkgname=mysql-gui-tools
    pkgver=5.0r14
    pkgrel=2
    arch=('i686' 'x86_64')
    pkgdesc="Set of programs to manage and interact with a MySQL server."
    url="http://www.mysql.com/products/tools/"
    license=('GPL')
    source=(http://mirrors.uol.com.br/pub/mysql/Downloads/MySQLGUITools/$pkgname-$pkgver.tar.gz
    bad-char.patch
    mysql-gui-tools-sigc_2.1.1_api_fixes.diff
    mysql-gui-tools-5.0_p12-deprecated-gtk+-api.patch
    mysql-gui-tools-gcc43.patch
    mysql-gui-tools.chema_change_freeze_bug.patch)
    depends=('gtkmm' 'gtkhtml' 'libmysqlclient' 'pcre')
    replaces=('mysql-administrator' 'mysql-query-browser')
    conflicts=('mysql-administrator' 'mysql-query-browser')
    provides=('mysql-gui-common' 'mysql-administrator' 'mysql-query-browser')
    makedepends=('pkgconfig' 'lua' 'libxml2' 'libgnomeprint')
    options=('!makeflags')
    build() {
    cd $startdir/src/$pkgname-$pkgver
    # Patch from mysql.com to fix the freeze when selecting a schema
    patch -p1 < ../mysql-gui-tools.chema_change_freeze_bug.patch || return 1
    # Patch to make 5.0r14 compile
    patch -Np1 < $startdir/src/bad-char.patch
    patch -Np1 < $startdir/src/mysql-gui-tools-sigc_2.1.1_api_fixes.diff
    patch -Np1 < $startdir/src/mysql-gui-tools-gcc43.patch
    patch -Np0 < $startdir/src/mysql-gui-tools-5.0_p12-deprecated-gtk+-api.patch
    cd $startdir/src/$pkgname-$pkgver/common
    sh autogen.sh
    ./configure --prefix=/usr --datarootdir=/usr/share --with-gtkhtml=libgtkhtml-3.14 || return 1
    make || return 1
    make DESTDIR=$startdir/pkg install || return 1
    cd ..
    cp -R common mysql-gui-common
    cd $startdir/src/$pkgname-$pkgver/administrator
    sh autogen.sh
    ./configure --prefix=/usr --datarootdir=/usr/share --with-gtkhtml=libgtkhtml-3.14 || return 1
    make || return 1
    make DESTDIR=$startdir/pkg install || return 1
    cd $startdir/src/$pkgname-$pkgver/query-browser
    sh autogen.sh
    ./configure --prefix=/usr --datarootdir=/usr/share --with-gtkhtml=libgtkhtml-3.14 || return 1
    make CFLAGS="${CFLAGS} -D_GNU_SOURCE" || return 1
    make DESTDIR=$startdir/pkg install || return 1
    #cd $startdir/src/$pkgname-$pkgver/mysql-workbench
    #patch -p1 < ../../mysql-gui-tools-5.0_p12-workbench-lua.patch
    #./configure --prefix=/usr --with-gtkhtml=libgtkhtml-3.14 || return 1
    #make || return 1
    #make DESTDIR=$startdir/pkg install
    # Some adjusts to make mysql-workbench run
    #cd $startdir/pkg/usr/bin
    #mv mysql-workbench mysql-wb
    #mv mysql-workbench-bin mysql-wb-bin
    #install -m755 $startdir/src/mysql-workbench.sh mysql-workbench
    #rm -rf $startdir/pkg/usr/lib/
    # Fixed startup scripts
    install -m755 $startdir/mysql-administrator $pkgdir/usr/bin
    install -m755 $startdir/mysql-query-browser $pkgdir/usr/bin
    md5sums=('b8efefbf20b7264c8f3afd34424467d7'
    '4279c75bb5e6c2bfcb16c98817d55b80'
    '4625629385142862cd01d37f814d5e80'
    '33205d45329ab4fa4096b6b298a60b2c'
    '1368384dac87bc0a64adb774ab2e6cbd'
    '2ff840932405f7a6a6863f633a639fe9')
    New mysql-gui-tools.chema_change_freeze_bug.patch: (only changes to paths in file. Don't know if this was really needed, but I belive so.)
    diff -ruN mysql-gui-tools-5.0r11.ORIG/query-browser/source/linux/MQQueryDispatcher.cc mysql-gui-tools-5.0r11/query-browser/source/linux/MQQueryDispatcher.cc
    --- mysql-gui-tools-5.0r11.ORIG/query-browser/source/linux/MQQueryDispatcher.cc 2007-02-21 01:31:19.000000000 +0000
    +++ mysql-gui-tools-5.0r11/query-browser/source/linux/MQQueryDispatcher.cc 2007-11-09 15:31:38.000000000 +0000
    @@ -558,8 +558,8 @@
    Gtk::Main::instance()->run();
    - while(!req->is_complete())
    +// while(!req->is_complete())
    +// ;
    return sps;
    I hope this helps anyone else who needs to fix this!

  • Press button to execute MYSQL query on database

    Hi, I was looking for a solution to this:
    I want to create a button in a jsp page.
    When a user presses the button, it executes a SQL Query on a database.
    There is no need to take any info from the jsp page.
    Is there a solution to this problem?
    For example, when I press the button, I want it to execute a query like this:
    INSERT INTO table3(name)
    SELECT name FROM table1,table2
    WHERE table1.timestamp>table2.timestamp
    GROUP BY name;This query is functional in MySQL, and all I need is to convince that button to execute the query.
    table1 contains 100 values
    table2 contains only one row, and only one timestamp value and is a value inserted by user through a jsp page
    Extra:
    After this is executed, it would be nice to display a confirmation in the initial page.
    Also, it would be nice to be able too see what values were inserted into table 2
    I have been searching a lot for a solution in many forums, but with no results yet.
    I can't believe jsp doesn't have a solution for this.
    Please help me.
    Thanks :)

    Look into JDBC
    The following will give you a start.
    http://java.sun.com/products/jdbc/
    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/
    http://java.sun.com/products/jdbc/download.html
    http://java.sun.com/docs/books/tutorial/jdbc/basics/
    http://java.sun.com/developer/onlineTraining/Database/JDBCShortCourse/
    rykk

  • Counting rows in a mysql query

    Hey
    How do i count the rows in a mysql query?
    I have tried to make a while loop (as you can see in the code), but if i make this while loop i cant use the same query to get the database data.
    Doesnt java have a function that counts the rows?
    public DefaultTableModel searchCategory(String searchString){
            String returnString = "";
            try{
                RS = connection.executeQuery("SELECT name, price, products_type_id FROM katrinelund_products WHERE products_type_id = (SELECT products_type_id FROM katrinelund_products_type WHERE name LIKE '%"+searchString+"%')");
                int rowCount = 0;
                while(RS.next()){
                    rowCount++;
                String[] columnNames = {"Navn", "Pris", "Produkt type"};
                Object[][] data = new Object[rowCount][columnNames.length];
                int i=0;
                while(RS.next()){
                    data[0] = RS.getString(1);
    data[i][1] = RS.getString(2);
    data[i][2] = RS.getString(3);
    i++;
    table = new DefaultTableModel(data, columnNames);
    catch(SQLException E){
    System.out.println("Der skete en fejl" + E.getMessage());
    return table;
    }NOTE: the connection to the database is stored in the connection variable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    yawmark wrote:
    The SELECT COUNT(*) cannot be fetched among other data, so in this case you must send two queries. Then there is much simplier to use the method I mentioned above.While it may be "simpler", it's not supported in a non-trivial number of drivers. So there are a number of situations in which your "simple" solution will not work. I assume you've been fortunate enough to work only with drivers that do support the functionality you recommend, but I can also only assume that you haven't had much experience beyond that.I apologize for my spelling errors. I'm not a native englishman.
    yawmark wrote:
    Knowing the amount of rows a resultset returns can be interesting if you're making some kind of search engine. Knowing the amount of data returned for a particular query can certainly be useful, and we've presented some reasonable means of obtaining that kind of information that don't rely on potentially unsupported features.
    I don't now about unsupported features. The ResultSet is (as far as I know) not tied to a specific SQL database. This, and all of it's methods is in the java.sql.ResultSet interface. Then all classes implementing this must have these methods. Am I not right?
    yawmark wrote:
    Stop dealing with however it's necessary or not.Sorry, partner, but you don't get to decide what I post here.
    This guy wants this problem to be solved, so apparentley he has a usage for it...And what you're apparently failing notice is that there are other solutions (better, in many cases) than the solution which you posted. Don't make the mistake of thinking your suggestion is golden. It isn't. Besides, there are no shortage of beginners that want the "problem" of i = i++ to be "solved"; no doubt they think they have an apparent usage for it, too. ~I'm well aware of that you decide on your own what to post. I just don't see how it is necessary to discuss the matter of necessity in this case. The problem still remains.
    I don't want any fuss here. I'm just so sick of everyone who yells "you don't need to know that". I haven't decried any of the other solutions (at least it wasn't my point), all I said was that it's not a good idea to send multiple queries to the database when you already have the answer three rows of code away. In some rare situations, the data may have been changed during the short period of time as the database is finished with the first query before you send the next one.

  • MySQL query not outputting results

    Hi Guys,
    I want to retrieve a record from my database which has the latest date and output its contents onto the webpage. This is what I have done so far:
    ResultSet rs = DB.exQuery("SELECT max(transaction_date) as 'lastest_date',transaction_value,transaction_type"
                                  + "FROM transaction_log WHERE user_id =" + user.getId() + " AND is_credit = '1'");
    try {
         trans_date = rs.getString("lastest_date");
         credit = rs.getString("transaction_value");
         trans_method = rs.getString("transaction_type");
    } catch(SQLException ex) {}It compiles fine but when I run the servlet I get "java.lang.NullPointerException" on line 92 (+trans_date = rs.getString("lastest_date");+). I get the same error even if I add the rs.next() method. Note that the database will always only output ONE record. I checked the MySQL query (ran it on the server directly) and it worked fine.

    try {
    ResultSet rs = DB.exQuery("SELECT max(transaction_date) as lastest_date, transaction_value,transaction_type"
                                  + "FROM transaction_log WHERE user_id =" + user.getId() + " AND is_credit = '1'");
    if ( rs.next () ) {can you explain
    *     trans_date = rs.getString("lastest_date");* // trans_date is a string type or date type... and max(transaction_date) as lastest_date returns which type...
         credit = rs.getString("transaction_value");
         trans_method = rs.getString("transaction_type");
    } catch(SQLException ex) {}

  • Conversion of Mysql query in oracle acceptable query format

    Hi
    I have successfully converted my MySql database in oracle. Now the problem is how to execute already written hundreds of Mysql query on the oracle. There are many syntax variation in Mysql query format which is not acceptable for oracle.
    For Example
    Select case_id as 'this is alias' from cases
    The above query can run on Mysql database but have problem while executing Oracle, because single quotes should be replaced with double quotes before executing it on oracle. There are also many other syntax conflicts.
    I have tried to resolve the problem through SwisSQLAPI but problem still exist as SwisSQLAPI is not dealing with all syntax conflict. In my case (select if (expresion, true,false)) must be replace with decode (expression, value,true,false) function of oracle and this conversion is not supported by SwisSQLAPI.
    Please help me in resolving this problem
    Thanks

    The problem with trying to port from one language (mysql SQL) to another (oracle SQL) is that there's generally no hard rules for a computer to follow, that it will get it 100% correct.
    Look at babelfish when you translate a foreign language to English. The end result is readable (usually), but it's rarely completely correct.
    The problem is when you feed something into Oracle SQL, it needs to be 100% correct.
    All you can really do here is rewrite these queries. It shouldn't actually take as long as you think, because 50% of queries will generally need very minor changes you can do in a minute, and 25% won't need any changes at all.

  • Weird problem with mysql query and data table buttons !!!!

    Hi,
    I'm using jsc 2 update 1 on windows and mysql 4.1 . I have a page with a data table. One column of the data table contains "Details" buttons.
    Source query for the table is :
    SELECT tbl_tesserati.idtbl_tesserati idTesserato,
    tbl_tesserati.num_tessera,
    tbl_tesserati.nome,
    tbl_societa.codice_meccanografico
    FROM tbl_tesserati
    INNER JOIN tbl_rel_tesserato_discipline_societa ON tbl_tesserati.idtbl_tesserati = tbl_rel_tesserato_discipline_societa.id_tesserato
    INNER JOIN tbl_cariche ON      tbl_rel_tesserato_discipline_societa.id_carica = tbl_cariche.idtbl_cariche
    INNER JOIN tbl_qualifiche ON      tbl_rel_tesserato_discipline_societa.id_qualifica = tbl_qualifiche.idtbl_qualifiche
    INNER JOIN tbl_discipline ON      tbl_rel_tesserato_discipline_societa.id_disciplina = tbl_discipline.idtbl_discipline
    INNER JOIN tbl_societa ON      tbl_rel_tesserato_discipline_societa.id_societa = tbl_societa.idtbl_societa
    LEFT JOIN tbl_province ON tbl_societa.provincia_sede_sociale = tbl_province.idtbl_province
    LEFT JOIN tbl_comuni ON tbl_societa.comune_sede_sociale = tbl_comuni.idtbl_comuni
    LEFT JOIN tbl_rel_tesserato_discipline_praticate ON tbl_rel_tesserato_discipline_praticate.tessera_id=
    tbl_rel_tesserato_discipline_societa.idtbl_rel_tesserato_discipline
    LEFT JOIN tbl_discipline_praticate ON tbl_discipline_praticate.idtbl_disciplina_praticate=tbl_rel_tesserato_discipline_praticate.disciplina_praticata_id
    WHERE
    tbl_tesserati.cognome LIKE ?
    AND tbl_tesserati.nome LIKE ?
    AND tbl_rel_tesserato_discipline_societa.id_societa LIKE ?
    AND tbl_tesserati.idtbl_tesserati LIKE ?
    AND tbl_cariche.idtbl_cariche LIKE ?
    AND tbl_qualifiche.idtbl_qualifiche LIKE ?
    AND tbl_tesserati.data_nascita >= ?
    AND tbl_tesserati.data_nascita<= ?
    AND tbl_discipline.idtbl_discipline LIKE ?
    AND codice_affiliazione LIKE ?
    AND tbl_societa.denominazione LIKE ?
    AND YEAR(tbl_rel_tesserato_discipline_societa.data_scadenza) LIKE ?
    AND (tbl_province.nome LIKE ? OR tbl_province.nome IS NULL)
    AND ( tbl_comuni.nome LIKE ? OR tbl_comuni.nome IS NULL)
    The tbl_tesserati.data_nascita is a mysql date field.
    The click event handler code for the "Details" Button is:
    public String btnModificaTesserato_action() {
            try{
                TableRowDataProvider rowData= (TableRowDataProvider)getBean("currentRowTesserati");
                getRequestBean1().setId_tesserato((Long)rowData.getValue("idTesserato"));          
            } catch(Exception ex) {
                log("errore nella query",ex);
            return "dettaglioTesseratoSocieta";
        }When i run the project and open the page the table is correctly rendered and populated with some rows. But when i click on details button nothing happens, the page is simply reloaded.
    If i set a breakpoint in the code line   TableRowDataProvider rowData= (TableRowDataProvider)getBean("currentRowTesserati");the debbuger does not stop the code execution ! As if the button was never clicked!
    I tried to modify the source query to :
    SELECT tbl_tesserati.idtbl_tesserati idTesserato,
    tbl_tesserati.num_tessera,
    tbl_tesserati.nome,
    tbl_societa.codice_meccanografico
    FROM tbl_tesserati
    INNER JOIN tbl_rel_tesserato_discipline_societa ON tbl_tesserati.idtbl_tesserati = tbl_rel_tesserato_discipline_societa.id_tesserato
    INNER JOIN tbl_cariche ON      tbl_rel_tesserato_discipline_societa.id_carica = tbl_cariche.idtbl_cariche
    INNER JOIN tbl_qualifiche ON      tbl_rel_tesserato_discipline_societa.id_qualifica = tbl_qualifiche.idtbl_qualifiche
    INNER JOIN tbl_discipline ON      tbl_rel_tesserato_discipline_societa.id_disciplina = tbl_discipline.idtbl_discipline
    INNER JOIN tbl_societa ON      tbl_rel_tesserato_discipline_societa.id_societa = tbl_societa.idtbl_societa
    LEFT JOIN tbl_province ON tbl_societa.provincia_sede_sociale = tbl_province.idtbl_province
    LEFT JOIN tbl_comuni ON tbl_societa.comune_sede_sociale = tbl_comuni.idtbl_comuni
    LEFT JOIN tbl_rel_tesserato_discipline_praticate ON tbl_rel_tesserato_discipline_praticate.tessera_id=
    tbl_rel_tesserato_discipline_societa.idtbl_rel_tesserato_discipline
    LEFT JOIN tbl_discipline_praticate ON tbl_discipline_praticate.idtbl_disciplina_praticate=tbl_rel_tesserato_discipline_praticate.disciplina_praticata_id
    WHERE
    tbl_tesserati.cognome LIKE ?
    AND tbl_tesserati.nome LIKE ?
    AND tbl_rel_tesserato_discipline_societa.id_societa LIKE ?
    AND tbl_tesserati.idtbl_tesserati LIKE ?
    AND tbl_cariche.idtbl_cariche LIKE ?
    AND tbl_qualifiche.idtbl_qualifiche LIKE ?
    AND tbl_tesserati.data_nascita >= ?
    OR tbl_tesserati.data_nascita<= ?
    AND tbl_discipline.idtbl_discipline LIKE ?
    AND codice_affiliazione LIKE ?
    AND tbl_societa.denominazione LIKE ?
    AND YEAR(tbl_rel_tesserato_discipline_societa.data_scadenza) LIKE ?
    AND (tbl_province.nome LIKE ? OR tbl_province.nome IS NULL)
    AND ( tbl_comuni.nome LIKE ? OR tbl_comuni.nome IS NULL)
    Using this query everything works well !! The click handler works and the debugger too !!
    I changed only the AND in OR !!!
    I also tried to change mysql-x-x-connector driver but without solving my problem.
    Can someone help me ?
    Thanks
    Giorgio

    You'll find that it is more to do with the way MySql deals with dates than anything else! Depending on how your date field is setup, then try using a BETWEEN statement for those 2 lines in your first query e.g.
    AND ( tbl_tesserati.data_nascita BETWEEN ? AND ?)
    The date column needs to be in the ISO format to work. If you examine your second query output, you might discover that the output is only going to refer to one parameter (probably the OR one). Did you manage to view the output logs from the application server? You would have got an idea from there with a message like stating a conversion error'.
    Alternatively, you could try using the to_days() function and convert it directly to a number which would be a lot easier to deal with. For example:
    AND to_days(tbl_tesserati.data_nascita >= ? )
    AND to_days( tbl_tesserati.data_nascita<= ? )
    Or try the BETWEEN version with to_days() and see what you get.
    More info about date formatting (v5) here:
    http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_to-days
    Before I forget, sometimes you may need to treat dates as Strings rather 'Long' as you did.
    As a matter of interest, did you try your query in a different piece of software?
    If my queries are a little more complicated, I tend to try MySql queries out in the free MySql query browser and also double check in another to verify certain issues. I found it easier to develop SQL in a seperate program then import the final version to JSC making the required modifications for parameters.
    Message was edited by:
    aerostra

  • Trouble Compiling mysql-query-browser

    After building all of the necesary prerequsites I am trying to compile mysql-query-browser on Solaris 10 (x86). I am getting some errors (shown below) when I run the configure script for the mysql-gui-common components. Can anyone tell me how I might fix these errors?
    ---configure output---
    checking for a BSD-compatible install... /opt/sfw/bin/ginstall -c
    checking whether build environment is sane... yes
    checking for gawk... gawk
    checking whether make sets $(MAKE)... yes
    checking build system type... i386-pc-solaris2.10
    checking host system type... i386-pc-solaris2.10
    checking for gcc... gcc
    checking for C compiler default output... a.out
    checking whether the C compiler works... yes
    checking whether we are cross compiling... no
    checking for suffix of executables...
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking for gcc option to accept ANSI C... none needed
    checking for style of include used by make... GNU
    checking dependency style of gcc... gcc3
    checking for g++... g++
    checking whether we are using the GNU C++ compiler... yes
    checking whether g++ accepts -g... yes
    checking dependency style of g++... gcc3
    checking for ranlib... ranlib
    checking for pkg-config... /usr/bin/pkg-config
    checking for glib-2.0 libxml-2.0 >= 2.6.2... yes
    checking GLIB_CFLAGS... -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/include/libxml2
    checking GLIB_LIBS... -L/usr/local/lib -lglib-2.0 -lxml2 -lpthread -lz -lm -lsocket -lnsl
    checking for gthread-2.0 libxml-2.0 >= 2.6.2... yes
    checking GTHREAD_CFLAGS... -threads -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/include/libxml2
    checking GTHREAD_LIBS... -threads -L/usr/local/lib -lgthread-2.0 -lglib-2.0 -lxml2 -lpthread -lz -lm -lsocket -lnsl
    checking for gtk+-2.0... yes
    checking GTK_CFLAGS... -I/usr/local/include/gtk-2.0 -I/usr/local/lib/gtk-2.0/include -I/usr/local/include/atk-1.0 -I/usr/local/include/pango-1.0 -I/usr/openwin/include -I/usr/sfw/include -I/usr/sfw/include/freetype2 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include
    checking GTK_LIBS... -L/usr/local/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0
    checking for libglade-2.0 gtkmm-2.0... yes
    checking GNOME_CFLAGS... -I/usr/local/include/gtk-2.0 -I/usr/local/lib/gtk-2.0/include -I/usr/local/include/atk-1.0 -I/usr/local/include/pango-1.0 -I/usr/openwin/include -I/usr/sfw/include -I/usr/sfw/include/freetype2 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include/gtkmm-2.0 -I/usr/local/lib/gtkmm-2.0/include -I/usr/local/lib/sigc++-1.2/include -I/usr/local/include/sigc++-1.2 -I/usr/include/libglade-2.0 -I/usr/include/libxml2
    checking GNOME_LIBS... -L/usr/local/lib -lglade-2.0 -lxml2 -lpthread -lz -lsocket -lnsl -lgtkmm-2.0 -lgdkmm-2.0 -latkmm-1.0 -lgtk-x11-2.0 -lpangomm-1.0 -lglibmm-2.0 -lsigc-1.2 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0
    checking for mysql_config... -I'/usr/sfw/include/mysql'
    checking for mysql_config... Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    Options:
    --cflags         [-I'/usr/sfw/include/mysql']
    --libs           [-R/usr/sfw/lib -R/usr/sfw/lib/mysql -L/usr/sfw/lib -L'/usr/sfw/lib/mysql' -lmysqlclient -lz -lposix4 -lcrypt -lgen -lsocket -lnsl -lm] --socket         [tmp/mysql.sock]
    --port           [3306]
    --version        [4.0.15]
    --libmysqld-libs [-R/usr/sfw/lib -R/usr/sfw/lib/mysql -L/usr/sfw/lib -L'/usr/sfw/lib/mysql' -lmysqld -lpthread -lz -lposix4 -lcrypt -lgen -lsocket -lnsl -lm  -lpthread  -lrt]
    checking for pcre-config... yes
    checking for pcre-config... -L/opt/sfw/lib -lpcre
    configure: creating ./config.status
    config.status: creating Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library/source/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library_grt/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library_grt/source/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library_grt_modules/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library_grt_modules/source/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library_gc/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library_gc/source/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating source/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating source/grtsh/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating source/linux/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating source/linux/canvas/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating images/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating images/png/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating images/icons/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating images/icons/png/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating res/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating res/linux/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library/tests/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library/tests/read_international/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library/tests/test_detect_charset/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library/tests/test_mysql_api/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library/tests/test_parse_sql_statemets/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library/tests/test_translations/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: creating library/tests/test_xml/Makefile
    sed: command garbled: s,@MYSQL_LIBS@,Usage: /usr/sfw/bin/mysql_config [OPTIONS]
    config.status: executing depfiles commands

    I agree that it is entirely possible that the problem lies with mySQL and not Sun, however the query I posted on their forums is sitting in deathly silence so I'm now trying elsewhere.
    After making the change you mentioned it configures clean but it doesn't buil properly afterward, I presume this is the same for you.

  • Help with mysql query plz anyone i am begging!!!

    Hi everyone pls forgive me i am new to java. can someone pls tel me where i am going wrong wit this mysql query?
    <sql:query var="parish" maxRows="1" dataSource="jdbc/gav">
    SELECT ParishName, OwnerOccupierHousehold, OwnerOccupierPercOfOverall, OwnerOccupierCo2Emissions,
    SocialRentedHousehold, SocialRentedPercOfOverall, SocialRentedCo2Emissions, PrivateRentedHousehold,
    PrivateRentedPercOfOverall, PrivateRentedCo2Emission, TotalHouseholds, TotalPerc, Average,
    Total2001, TotalEstimatedTotal2006, EmissionsPerPerson, EmissionPerHousehold, EmissionsPerParish,
    EnergyChampionsNeeded, NumberOfPeopleAtWork, NumberOfSchoolAgeChildren
    FROM base_data as b
    WHERE b.id = ? <sql:param value="${param.id}"/>
    <sql:param value="${param.id}"/>
    </sql:query>
    <c:set var="parish" scope="request" value="${parish.rows[0]}"/>
    here is the error i get:
    java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
    please any help would be appreciated!!! Thanks in advance guys .

    here is my code for the form on the index page:
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
    <sql:query var="parish" dataSource="jdbc/gav">
    SELECT id, ParishName FROM base_data
    </sql:query>
    <form action="response.jsp">
    Select a Parish: <select name="id">
    <c:forEach var="parish" items="${parish.rows}">
    <option value="${parish.id}">${parish.ParishName}</option>
    </c:forEach>
    </select><br><input type="submit" value="submit" name="submit" /></form>
    here is the code for the response page:
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
    <sql:query var="parish" maxRows="1" dataSource="jdbc/gav">
    SELECT b.id, b.ParishName, b.OwnerOccupierHousehold, b.OwnerOccupierPercOfOverall, b.OwnerOccupierCo2Emissions,
    b.SocialRentedHousehold, b.SocialRentedPercOfOverall, b.SocialRentedCo2Emissions, b.PrivateRentedHousehold,
    b.PrivateRentedPercOfOverall, b.PrivateRentedCo2Emission, b.TotalHouseholds, b.TotalPerc, b.Average,
    b.Total2001, b.TotalEstimatedTotal2006, b.EmissionsPerPerson, b.EmissionPerHousehold, b.EmissionsPerParish,
    b.EnergyChampionsNeeded, b.NumberOfPeopleAtWork, b.NumberOfSchoolAgeChildren
    FROM base_data as b
    WHERE b.id = ? <sql:param value="${param.id}"/>
    </sql:query>
    <c:set var="parish" scope="request" value="${parish.rows[0]}"/>
    i display the results like this : ${parish.EmissionsPerParish}
    the user should be able to select a parish from a form and then sql query created and then i want to show the row results on the response page.
    could you tell me where so should be a simple process although not simple enough as it may seem.
    thanks for the advice keith

  • Problem in SQL query in MDB database

    Hello all,
                        I am using mdb database and want to read specific time stamp record based on time stamp. I am using simple sql query but I am getting one error. Please let me know where I am making mistake(s). One error is operator missing. VI and database is attached.
    My query is -SELECT * FROM Downloaded_120 where col2 between 13:00:00 04-06-2013 and 14:00:00 04-06-2013
    Thanks.
    Kudos are always welcome if you got solution to some extent.
    I need my difficulties because they are necessary to enjoy my success.
    --Ranjeet
    Attachments:
    VI and database.zip ‏372 KB

    http://digital.ni.com/public.nsf/allkb/4012B21BA0876907862576110070FC0A
    You're missing the #s, too.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • Executing SQL query in portal database

    Hi ,
       I wish to do a simple POC . I need to create a table from NWDS , populate it with some data and then access the table data using an sql query . I am aware how to create a table but I am not sure where exactly to write the query .
    What I would like to understand is
    1) If I create a table where would that table get created (The database) ?
    2) Where would I write that query in NWDS ?
    3) How would I execute that query in that database ?
    Please help for the same .
    (Needless to say that I always award points )
    Regards
    Deepak Singh

    Hi Gopal ,
       Thanks for the reply .This is what I did . I am pasting the whole code of the class that I am using to do the POC .
    package com.gravity;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.util.Hashtable;
    import javax.naming.InitialContext;
    import javax.sql.DataSource;
    /*import sun.jdbc.odbc.ee.DataSource;/
    @author Administrator
    To change the template for this generated type comment go to
    Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
    public class DataHandling {
    public static void DataPost(){
         Connection con = null ;
         try {
    Added code
            Hashtable env = new Hashtable();
              env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
              System.out.println("initial_context_factory put ");
              env.put(javax.naming.Context.PROVIDER_URL, "gms29:50004");
              System.out.println("provide_url put ");
              env.put(javax.naming.Context.SECURITY_PRINCIPAL, "j2ee_admin");
              System.out.println("security_principal put ");
              env.put(javax.naming.Context.SECURITY_CREDENTIALS, "gravity");
              env.put("domain", "true");
              env.put("force_remote", "true");
              System.out.println("security_credentials put ");
              InitialContext iCtxt = new InitialContext(env);
              System.out.println("Object made for initial context ");
              DataSource ds = (DataSource) iCtxt.lookup("jdbc/my_db");
              System.out.println("Datasource obtained ");
              try {
                   con = ds.getConnection();
                   Statement stmt = con.createStatement();
                        String query1 ="insert into EmpData (EMPCODE,EMPNAME) VALUES('naveen',125188)";
                        String query2 ="insert into EmpData (EMPCODE,EMPNAME) VALUES('deepak',125189)";
                        String query3 ="insert into EmpData (EMPCODE,EMPNAME) VALUES('rajeev',125190)";
                   stmt.executeUpdate(query1);
                   stmt.executeUpdate(query2);
                   stmt.executeUpdate(query3);
                  }catch (Exception e) {
                   e.printStackTrace();
             }catch (Exception e) {
                    e.printStackTrace();
                                         } finally {
                                            try {
                                            con.close();
                                                }catch (Exception e) {
                                                e.printStackTrace();
    public static void main (String[] args){
         System.out.println("Hello");
         DataPost();
    I have imported all the driver jar files and sapj2eeclient.jar in the classpath .
    Also the drivers found in the path
    172.16.161.11\usr\sap\EP1\DVEBMGS00\j2ee\cluster\server0\bin\ext\com.sap.portal.jdbcdrivers
    have all been added to the classpath .(Not sure if this is required)
    Let me know what you find wrong in my code and in the meanwhile I will try to implement what you suggested .
    Regards
    Deepak Singh

  • Mysql Query VS Vector Object

    I run mysql query using Java, and the results of it are put in a vector object. Due to the vector object is made by 1 element (it's sure because I wrote the database) I'd like to take it and put it in a string variable, but Java returns me a lot of exceptions; here is the code:
    public Vector eseguiQuery(String query) {
         Vector v = null;
         String [] record;
         int colonne = 0;
         try {
            Statement stmt = db.createStatement();     // Creo lo Statement per l'esecuzione della query
            ResultSet rs = stmt.executeQuery(query);   // Ottengo il ResultSet dell'esecuzione della query
            v = new Vector();
            ResultSetMetaData rsmd = rs.getMetaData();
            colonne = rsmd.getColumnCount();
            while(rs.next()) {   // Creo il vettore risultato scorrendo tutto il ResultSet
               record = new String[colonne];
               for (int i=0; i<colonne; i++) record[i] = rs.getString(i+1);
               v.add( (String[]) record.clone() );
            rs.close();     // Chiudo il ResultSet
            stmt.close();   // Chiudo lo Statement
         } catch (Exception e) { e.printStackTrace(); errore = e.getMessage(); }
         return v;
    public String autentica(String query){
              String s = (String) db.eseguiQuery(query).get(0);
              System.out.println(s);
              return s;
         }...Please help me!

    1. You're not calling ResultSet.next() to move the result set onto the first row of results.
    2. (Edit) Deleted because you were in fact closing your objects, though you should still use a finally block to make absolutely certain.
    3. The exceptions tell you what the problem is - when you post a question please include these.
    Edited by: dcminter on 06-Aug-2008 17:04

  • The query against the database caused an error in https: site

    Hi
    I have created a new Data source and External content type in sharePoint 2013
    I have also given all the permission to this Content type (including "Users(Windows)")
    I also having edit permission in the Sql-database.
    I have tied almost all the possibilities given in the net for this error.
    still the error("the query against the database caused an error") is there.
    Is this because of "https:/ " in the url?
    Can any one give a suggestion / solution for this?
    Thanks
    S H A J A N

    Hi,
    Can you please check ULS Log as well as event viewer, to see if there's any related error reported?
    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

  • Generate XML based on MySQL Query

    Hello guys,
    I need to create a XML file like this one(same structure) but based on MySQL query:
    <chart>
       <chart_type>pie</chart_type>
       <chart_data>
          <row>
             <null/>
             <string>2007</string>
             <string>2008</string>
             <string>2009</string>
          </row>
          <row>
             <string>Region A</string>
             <number>10</number>
             <number>30</number>
             <number>63</number>
          </row>
       </chart_data>
    </chart>
    I found a couple of good articles but I do not know how to get the same structure, I tried this:
    <?php
    header("Content-type: text/xml");
    $host = "localhost";
    $user = "test";
    $pass = "test";
    $database = "test";
    $enlace = mysql_connect($host, $user, $pass) or die("Error MySQL.");
    mysql_select_db($database, $enlace) or die("Error base de datos.");
    $query = "SELECT AGENTE, count(*) FROM clientes group by agente";
    $resultado = mysql_query($query, $enlace) or die("Sin resultados.");
    $salida_xml = "<?xml version=\"1.0\"?>\n";
    $salida_xml .= "<chart>\n";
    $salida_xml .= "<chart_type>" . 'pie' . "</chart_type>\n";
        $salida_xml .= "<chart_data>\n";
        for($x = 0 ; $x < mysql_num_rows($resultado) ; $x++){
            $fila = mysql_fetch_assoc($resultado);
            $salida_xml .= "\t<row>\n";
            $salida_xml .= "\t\t<agente>" . $fila['AGENTE'] . "</agente>\n";
            $salida_xml .= "\t\t<cantidad>" . $fila['count(*)'] . "</cantidad>\n";
                // Corregiendo caracteres incorrectos
                $fila['texto'] = str_replace("&", "&amp;", $fila['texto']);
                $fila['texto'] = str_replace("<", "&lt;", $fila['texto']);
                $fila['texto'] = str_replace(">", "&gt;", $fila['texto']);
               // $salida_xml .= "\t\t<texto>" . $fila['texto'] . "</texto>\n";
            $salida_xml .= "\t</row>\n";
        }//segundo for
        $salida_xml .= "</chart_data>\n";
    $salida_xml .= "</chart>";
    echo $salida_xml;
    but I'm not getting the same structure, I am getting this:
    <chart>
    <chart_type>pie</chart_type>

    <chart_data>
    <row>
        </row>

    <row>
    <agente>Danilo</agente>
    <cantidad>8</cantidad>
    </row>
    <row>
        </row>

    <row>
    <agente>Evelyn</agente>
    <cantidad>5</cantidad>
    </row>
    <row>
        </row>

    <row>
    <agente>Maribel</agente>
    <cantidad>2</cantidad>
    </row>
    <row>
        </row>

    <row>
    <agente>Nestor</agente>
    <cantidad>11</cantidad>
    </row>
    <row>
        </row>

    <row>
    <agente>Noemy</agente>
    <cantidad>2</cantidad>
    </row>
    </chart_data>
    </chart>
    Can someone give me a hand plase?
    Thanks in advance

    Doing some extra research I almost get to the result that I need, I guess I am jus
    t having an small problem.
    Basically I need this
    [PHP]
    <chart>
       <chart_type>pie</chart_type>
       <chart_data>
          <row>
             <null/>
             <string>2007</string>
             <string>2008</string>
             <string>2009</string>
          </row>
          <row>
             <string>Region A</string>
             <number>10</number>
             <number>30</number>
             <number>63</number>
          </row>
       </chart_data>
    </chart>
    [/PHP]
    Currently I have this:
    [PHP]
    <chart>
        <chart_type>pie</chart_type>
        <chart_data>
            <row>
                <null></null>
                <agente>Danilo</agente>
                <agente>Evelyn</agente>
                <agente>Maribel</agente>
                <agente>Nestor</agente>
                <agente>Noemy</agente>
            </row>
            <row>
                <rutas>rutas</rutas>
                <cantidad></cantidad>
                <cantidad></cantidad>
                <cantidad></cantidad>
                <cantidad></cantidad>
                <cantidad></cantidad>
            </row>
        </chart_data>
    </chart>
    [/PHP]
    And I am using this code
    [PHP]<?php
    header("Content-type: text/xml");
    $host = "xxx";
    $user = "xxxx";
    $pass = "xxxx";
    $database = "xxxx";
    $enlace = mysql_connect($host, $user, $pass) or die("Error MySQL.");
    mysql_select_db($database, $enlace) or die("Error base de datos.");
    $query = "SELECT AGENTE, count(*) FROM clientes WHERE PREVENTA LIKE 'Viernes' group by agente";
    $resultado = mysql_query($query, $enlace) or die("Sin resultados.");
    $salida_xml = "<?xml version=\"1.0\"?>\n";
    $salida_xml .= "<chart>\n";
    $salida_xml .= "\t<chart_type>" . 'pie' . "</chart_type>\n\n";
    $salida_xml .= "\t<chart_data>\n";
                $salida_xml .= "\t\t<row>\n";
                $salida_xml .= "\t\t\t<null>" . $fila5['NULL']. "</null>\n";
                for($y = 0 ; $y < mysql_num_rows($resultado) ; $y++){
                    $fila2 = mysql_fetch_assoc($resultado); 
                    $salida_xml .= "\t\t\t<agente>" . $fila2['AGENTE'] . "</agente>\n";
                    }//cierro for Y
                $salida_xml .= "\t\t</row>\n";
                $salida_xml .= "\t\t<row>\n";    
                $salida_xml .= "\t\t\t<rutas>" . 'rutas'. "</rutas>\n";
                for($z = 0 ; $z < mysql_num_rows($resultado) ; $z++){
                    $valor = mysql_fetch_assoc($resultado);
                    $salida_xml .= "\t\t\t<cantidad>" . $valor['count(*)'] . "</cantidad>\n";
                }//cierro for z
                $salida_xml .= "\t\t</row>\n";
        $salida_xml .= "\t</chart_data>\n";
    $salida_xml .= "</chart>";
    echo $salida_xml;
    ?>[/PHP]
    The issue I am having is that it is not showing the quantity, in this case "cantidad", does someone know why?

Maybe you are looking for