Having J2EE use mySQL

Hi
I'm using a standalone RedHat 9 system with J2EE 1.3.1 and mySQL 3.23.54.
All are working individually.
My current application creates new tables every time it starts, so I thought it would be dead simple to just ask J2EE to use mySQL. There are currently only two entity beans, and there's the place in the deploytool to enter the database JNDI name, username and password.
I can't find any information on how to do it though. What do I enter where? Sun's site doesn't seem to tell me about mySQL and J2EE, while mySQL has not one mention of J2EE in its documentation, nor in Kofler (my mySQL book).
I looked back through this forum too, and there's a link to a blog that doesn't seem relevant either.
Clues anyone? Much appreciated. If I see you, I'll buy you a pint. Warm, obviously (I'm in the UK). You'll like it, honest :-)
J

Hi! I think I may help you. I had the same problem. But I�m Brazilian, I�m learning the English language yet. I�ll try to explain you.
I am using J2EE version 1.3 with MySQL version 4.1.7 on Windows. You�ll have to configure the two following files:
- <J2EE_HOME>\bin\setenv.bat
- <J2EE_HOME>\config\resource.properties
1) Copy the Jar file of MySQL driver to <J2EE_HOME>\lib directory.
2) Open the setenv.bat and edit it. Add a reference to that Jar file.
3) Run the <J2EE_HOME>\bin\j2eeadmin.bat. There are two command lines to be executed, as below:
j2eeadmin.bat -addJdbcDriver <CLASS NAME OF THE DRIVER>
j2eeadmin.bat -addJdbcDatasource <JNDI-NAME> <URL>
For example:
j2eeadmin.bat -addJdbcDriver "com.mysql.jdbc.Driver"
j2eeadmin.bat -addJdbcDatasource "jdbc/mysql-connection/test" "jdbc:mysql://localhost/test?user=username&password=password"
4) Now, the <J2EE_HOME>\config\resource.properties must be modified, with the reference for the MySQL database. Open this file and you will see. But perhaps you will have to configure it editing this file. That�s because I noticed that the character "\" was added erroneously in a lot of places of the code of this file. It seems to be a bug. So I simply removed this character, replacing it.
5) Run the verbose, none error must appear, and the MySQL can be used with J2EE now! That�s all. Good luck!

Similar Messages

  • No suitable driver when using MySQL in J2EE server

    Hi everyone
    I use MySQL's mm driver version 2.0.11 in conjuction with j2ee server. I added it thru deploytool->Tools->Server configuration->Data source->Standard following the instuctions in the help document, either un-jared or not, setting the classpath or/and j2ee_classpath in userconfig.bat and still got the exception when connecting from client.
    Can anyone tell me why.
    Thanks
    James Chiang from Taiwan

    You may like this:
    http://forum.java.sun.com/thread.jsp?forum=136&thread=237527&message=929097#929097

  • How to use mysql in J2EE server?

    Hi all,
    I have been learning J2EE and playing around with Pointbase as my database and the IDE that I'm using is Forte For JAVA 4 EE.
    Now, I wanna use mysql in J2EE, EJB. But I do not know how to use mysql in j2ee server. I have try to altered the resources.property file by adding a few lines to called the MYSQL datasource and driver. But, it give me errors when i am doing the deployment process. Can any1 of u help me?
    Thanks in advance..

    Hi,
    I guess there must be some problem with your App Server Configuration settings:
    Kindly Check if you are using the following ones:
    Driver Name: com.mysql.jdbc.Driver
    Url: jdbc:mysql://[hostname][,failoverhost...][:port]/[dbname][?param1=value1][&param2=value2].....
    Thanks & regards,
    Paritosh
    Software Engineer
    L&T Infotech Ltd

  • Connection verification failed for data source using mySQL

    Hi,
    I having problem with mySQL datasource and getting the above error. This is only happening in our staging server. We are using ColdFusion 8 running JRUN4 and trying to connect to mySQL v 5.1.41. I tried adding DSN from my localhost using ColdFusion 9 developer edition and I am able to connect without error.I know that mysql server, username & password is valid. I can access the mysql also using mySQL gui tool from different pc and it works fine. I'm believe that this has something to do with mySQL driver? Can somebody shed some light on how can I fix my DSN connection problem? Thank you.
    here's the error:
    Connection verification failed for data source: forum
    com.mysql.jdbc.CommunicationsException: Communications link failure  due to underlying exception:   ** BEGIN NESTED EXCEPTION **   java.net.ConnectException MESSAGE: Connection timed out: connect  STACKTRACE:  java.net.ConnectException: Connection timed out: connect      at java.net.PlainSocketImpl.socketConnect(Native Method)      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)      at java.net.Socket.connect(Socket.java:519)      at java.net.Socket.connect(Socket.java:469)      at java.net.Socket.(Socket.java:366)      at java.net.Socket.(Socket.java:208)      at  com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:173)       at com.mysql.jdbc.MysqlIO.(MysqlIO.java:267)      at com.mysql.jdbc.Connection.createNewIO(Connection.java:2739)      at com.mysql.jdbc.Connection.(Connection.java:1553)      at  com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)       at  coldfusion.server.j2ee.sql.pool.JDBCPool.createPhysicalConnection(JDBCPool.java:589)       at  coldfusion.server.j2ee.sql.pool.ConnectionRunner$RunnableConnection.run(ConnectionRunner. java:67)       at java.lang.Thread.run(Thread.java:619)   ** END NESTED EXCEPTION **    Last packet sent to the server was 0 ms ago.

    http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6ef0253
    HTH
    Tim Carley
    www.recfusion.com
    [email protected]

  • How can I use mySQL with OC4J

    Hello,
    I have standalone OC4J and I want to use mySQL database (Oracle is no problem). My data-sources.xml for application (not global data-sources) is:
    <data-sources>
    <data-source class="com.evermind.sql.DriverManagerDataSource"
         connection-driver="org.gjt.mm.mysql.Driver"
         ejb-location="jdbc/MG_DBDS"
         inactivity-timeout="30"
         location="jdbc/MG_DBCoreDS"
         name="MG_DBDS"
         password=""
         pooled-location="jdbc/MG_DBPooledDS"
         url="jdbc:mysql://127.0.0.1:3306/test"
         username="root"
         xa-location="jdbc/xa/MG_DBXADS"/>
    </data-sources>
    Deploy return me:
    Error initializing data-source 'jdbc/MG_DBCoreDS': DriverManagerDataSource driver 'org.gjt.mm.mysql.Driver' not found
    Then I run this command:
    java -jar %OC4J_HOME%\admin.jar ormi://192.168.1.14:23791/ admin heslo -application Register -updateDataSource -oldLocation jdbc/MG_DBCoreDS -jar mysql-2.0.11-bin.jar
    this action is success and create in OC4J folder lib with jar file mysql-2.0.11-bin.
    When I use this configuration in application, I get connection but creating Statement cause SQL Exception - No suitable driver.
    When I try to restart OC4J, I get the same message as throught deploy - Error initializing data-source ...
    What is go wrong???? Could me help anyone?
    Thanks
    Libor

    pooling solution:
    1) put driver mysql.jar into any directory wich described in OC4J application.xml file like
    " <library path="D:\j2ee\home\lib">jdev-generated</library>"
    2) put a new datasource in data-sources.xml:
    <data-sources>
    <data-source name="MySqlDS"
    location="jdbc/MySqlDS"
    class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"
    max-connections="100"
    min-connections="5"
    inactivity-timeout="200"
    wait-timeout="10"
    username="scott"
    password="tiger"
    url="jdbc:mysql://localhost:3306/oln?useUnicode=true"/>
    </data-sources>
    OC4J needs a special pooling class in comparision with other containers. For example, JBoss has own implementation of pooling broker, so pooling is enabled by default.

  • J2ee and mysql

    hi guys, pls pardon if this has been asked b4...
    is it recommended to use j2ee with mysql? are they fully compatiable? if not, what database should be use with j2ee?
    thanks!

    Is your JdbcRowSetImpl this?
    http://developers.sun.com/prodtech/javatools/jscreator/reference/docs/apis/rowset/com/sun/rowset/JdbcRowSetImpl.html
    If so, then I notice there is an insertRow() method. Before you call that method, though, you have to call moveToInsertRow() to prepare, then call setInt() or setString() and so on to fill in the data.

  • SQL Verification Problem / Muse Form Issue (Server uses MySQL muse uses SQLite) I'm in desperate need of help

           Alright well here is my issue... I have been trying to fix it on my own for the past week non stop and I have finally came to a solid conclusion as to the cause of the issue.
       I always get the error "The server has encountered an error..." in red text when anyone tries to submit a form and also when I try and test it myself. This led me to test the server / site for compatibility or issues by using the test:
    mydomain.com /scripts/form_check.php
    I got the first two checks green (pass) and the third test threw a red check meaning I was having an issue with SQL verification. This then led me to days of trying to work with my hosting provider (one.com) trying to solve the problem and I was told that they use mySQL on their servers and that they couldn't do anything on their end to solve the issue. I read alot that we are recommended in this case to try and get our host to add the SQLite database to their server or whatever it is they would do, long story short I guess many people are able to ask their host to make SQLite work and most accept and add SQLite functionality to their servers but unfortunately my hosting provider doesn't want to do this and they said they were sorry and that I would need to either switch the script to work with mySQL or figure something else out...
       I took a lot of time building my site and I dont want to take the form out. I absolutely need it... I know many post on here saying "forms dont work, oh poop " or "adobe sucks I dont want to use business catalyst grrr" but I tried to find the source of the problem and I've successfully came to the conclusion that my issue is that my script wants to use SQLite but in order for my sites forms to work the server needs to have SQLite as well... My idea is that if I can configure the script and the site itself to use mySQL instead of SQLite the SQL verification will then not be an issue and my websites forms will function with no issues. I am curious if a member of the staff with adobe has experience with this particular issue and can help me out? or if a member of the adobe community has solved this problem? If not I am hoping that with the description I provided that someone with knowledge of mysql, sqlite or code in general could help me modify the script or write a new script that will allow the forms to work properly. I know its a long shot, I say that because this discussion is full of people who used muse in favor of dreamweaver because just like a large number of people in the muse discussion area, I'm a graphic designer, with plenty of computer experience, art and design skill and I am extremely familiar with photoshop. Muse is perfect in so many ways. In fact, like I mentioned above, I don't even have a complaint at this time about muse. I understand the form issue in this case, and I imagine in thousands of other users situations, is all just a matter of scripts and compatibility.. Its just a little issue between the SQLite scripts we are all given when we export our muse website and the SQL version our various hosting service may be using on their servers.
       Just incase I missed anything, to provide just a bit more info on the topic and myself for anyone who may be able to help:
    I can alter the text inside of the scripts easily if anyone happens to know any lines of code that easily solve this issue (making the muse contact forms, which are native to SQLite, functional on a server using mySQL)
    I was told one way I could make the forms work on a server using mySQL (or any version other than SQLite) If I were to make changes to adobe muses SQL version by converting the SQLite db to mySQL db (db = database)
    I am computer literate and I can take any directions necessary, I really just need to get this done, I really appreciate any help I can get!!
    Thank you in advance,
    Roy

    <?php
    If you see this text in your browser, PHP is not configured correctly on this hosting provider.
    Contact your hosting provider regarding PHP configuration for your site.
    PHP file generated by Adobe Muse CC 2014.1.6
    function formthrottle_check()
        if (!function_exists("sqlite_open"))
            return '1';
        $retCode ='5';
        if ($db = @sqlite_open('muse-throttle-db', 0666, $sqliteerror))
            $res = @sqlite_query($db, "SELECT 1 FROM sqlite_master WHERE type='table' AND name='Submission_History';",  $sqliteerror);
            if ($res == null or @sqlite_num_rows($res) == 0 or @sqlite_fetch_single($res) != 1)
                $created = @sqlite_exec($db, "CREATE TABLE Submission_History (IP VARCHAR(39), Submission_Date TIMESTAMP)",  $sqliteerror);
                if($created)
                    @sqlite_exec($db, "INSERT INTO Submission_History (IP,Submission_Date) VALUES ('256.256.256.256', DATETIME('now'))",  $sqliteerror);
                else
                    $retCode = '2';
            if($retCode == '5')
                $res = @sqlite_query($db, "SELECT COUNT(1) FROM Submission_History;",  $sqliteerror);
                if ($res != null and @sqlite_num_rows($res) > 0 and @sqlite_fetch_single($res) > 0)
                    $retCode = '0';
                else
                    $retCode = '3';
            @sqlite_close($db);
        else
            $retCode = '4';
        return $retCode;
    function formthrottle_too_many_submissions($ip)
        $tooManySubmissions = false;
        if (function_exists("sqlite_open") and $db = @sqlite_open('muse-throttle-db', 0666, $sqliteerror))
            $ip = @sqlite_escape_string($ip);
            @sqlite_exec($db, "DELETE FROM Submission_History WHERE Submission_Date < DATETIME('now','-2 hours')",  $sqliteerror);
            @sqlite_exec($db, "INSERT INTO Submission_History (IP,Submission_Date) VALUES ('$ip', DATETIME('now'))",  $sqliteerror);
            $res = @sqlite_query($db, "SELECT COUNT(1) FROM Submission_History WHERE IP = '$ip';",  $sqliteerror);
            if (@sqlite_num_rows($res) > 0 and @sqlite_fetch_single($res) > 25)
                $tooManySubmissions = true;
            @sqlite_close($db);
        return $tooManySubmissions;
    ?>

  • Error using mySQL

    Hi. I´m trying use mySQL with SRTutorialADFBC tutorial. I can create connections. I can view my tables, etc. But when I try run the jsp page, I get a error 500:
    java.sql.SQLException: No suitable driver
         at java.sql.DriverManager.getConnection(DriverManager.java:545)
         at java.sql.DriverManager.getConnection(DriverManager.java:140)
         at oracle.jbo.server.ConnectionPool.createConnection(ConnectionPool.java:189)
         at oracle.jbo.server.ConnectionPool.instantiateResource(ConnectionPool.java:135)
         at oracle.jbo.pool.ResourcePool.createResource(ResourcePool.java:536)
         at oracle.jbo.pool.ResourcePool.useResource(ResourcePool.java:326)
         at oracle.jbo.server.ConnectionPool.getConnectionInternal(ConnectionPool.java:87)
    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:110)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:239)
         at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:34)
         at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:880)
         at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:298)
         at java.lang.Thread.run(Thread.java:595)
    Can you help me?

    Thanks javaX. But the error continue... The message begin:
    500 Internal Server Error
    JBO-30003: The pool of applications (oracle.srtutorial.datamodel.AppModuleLocal) failed in the checkout module exception:
    oracle.jbo.JboException: JBO-29000: JBO-29000: JBO-29000: JBO-26061: Erro ao abrir a conexão JDBC.
         at oracle.jbo.common.ampool.ApplicationPoolImpl.doCheckout(ApplicationPoolImpl.java:2002)
         at oracle.jbo.common.ampool.ApplicationPoolImpl.useApplicationModule(ApplicationPoolImpl.java:2793)
         at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:453)
         at oracle.jbo.http.HttpSessionCookieImpl.useApplicationModule(HttpSessionCookieImpl.java:233)
         at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:424)
         at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:419)
    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:216)
         at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:117)
         at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:110)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:239)
         at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:34)
         at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:880)
         at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:298)
         at java.lang.Thread.run(Thread.java:595)
    Any new idea?

  • Using MySQL DB on Weblogic 10.3.2 for JMS Store and etc.

    Hi,
    I am planning to use MySQL DB w Weblogic 10.3.2 server.
    I am planning to use Persistent JMS Destinations and planning to use MySQL Datasource for JMS store.
    Can anyone please help me understand any serious issues or considerations of this combination?
    Thanks
    Sagar

    Hi,
    I am planning to use MySQL DB w Weblogic 10.3.2 server.
    I am planning to use Persistent JMS Destinations and planning to use MySQL Datasource for JMS store.
    Can anyone please help me understand any serious issues or considerations of this combination?
    Thanks
    Sagar

  • How Can I use Mysql's  PROCEDURE by Java Can you give me sample???

    �������^���������������H�iBEGIN�`END�u���b�N�j�@��TOP
    ORACLE�@MSSQL�@SSA�@MySQL�@
    ���{�I���������������������������B
    MySQL�������A ORACLE��MSSSQL��������������BEGIN�`END�u���b�N�����s�������������������������B
    ���������s�������������K���X�g�A�h�v���O�����������R���p�C�������K�v�����������B
    �i�����F�������������������A���w�E�������������K�r�����������j
    --drop PROCEDURE sp_hoge;
    --�f���~�^�����X��������
    delimiter //
    CREATE PROCEDURE sp_hoge()
    DETERMINISTIC
    BEGIN
    /* �������� */
    DECLARE mystr VARCHAR(20);
    DECLARE mycnt INTEGER(2);
    /* �l������ */
    SET mycnt = 0;
    SET mystr = '����';
    /* IF�� */
    IF mycnt = 0 THEN
    SET mystr = '�����Q';
    select mystr;
    ELSE
    select '�����R';
    END IF;
    /* CASE�� */
    CASE extract(month from now())
    WHEN 1 THEN SET mystr = '1��';
    WHEN 2 THEN SET mystr = '2��';
    WHEN 3 THEN SET mystr = '3��';
    WHEN 4 THEN SET mystr = '4��';
    ELSE SET mystr = '1�`4�����O';
    END CASE;
    select mystr;
    /* WHILE-LOOP */
    WHILE mycnt <= 5 DO
    SET mycnt = mycnt + 1;
    select mycnt;
    END WHILE;
    /* BEGIN-END�u���b�N������SELECT�������s */
    /* PROCEDURE�������\�iFUNCTION���������������j */
    select * from help_topic;
    END//
    delimiter ;
    --�X�g�A�h�v���V�[�W�����s
    call sp_hoge();
    �X�g�A�h�v���V�[�W�����T���v���i�J�[�\�����g�p������LOOP�����j�@��TOP
    ORACLE�@MSSQL�@SSA�@MySQL�@
    �J�[�\�����g�p����LOOP�������T���v�������B
    �����p�����[�^���w�����������������Y�������������������A���E���w�X�^�b�t�x�������������A�����������w�c���X�^�b�t�F�x���\���������B
    --drop PROCEDURE sp_hoge;
    --�f���~�^�����X��������
    delimiter //
    CREATE PROCEDURE sp_hoge(inum INTEGER(3))
    DETERMINISTIC
    BEGIN
    /* �������� */
    /* �J�[�\���g�p�����f�[�^�L�����f���g�p */
    DECLARE done INT DEFAULT 0;
    /* �������O������ */
    DECLARE v_mystr VARCHAR(20);
    /* �J�[�\���g�p�� */
    DECLARE v_empnm VARCHAR(40);
    DECLARE v_job VARCHAR(20);
    /* �J�[�\������ �� �����������������`���� */
    DECLARE cur1 CURSOR FOR
    select empnm,job from kemp where deptno = inum;
    /* �f�[�^��������LOOP�E�o�p���������� */
    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
    /* �J�[�\���I�[�v�� */
    OPEN cur1;
    /* LOOP */
    LOOPPROC:REPEAT
    FETCH cur1 INTO v_empnm,v_job;
    IF NOT done THEN
    IF v_job = '�X�^�b�t' THEN
    SET v_mystr = '�c���X�^�b�t�F';
    ELSE
    SET v_mystr = '';
    END IF;
    select CONCAT(v_mystr,v_empnm);
    /* ������������LOOP���E�o����������LEAVE�� */
    /* LEAVE LOOPPROC; */
    END IF;
    UNTIL done END REPEAT;
    /* �J�[�\���N���[�Y */
    CLOSE cur1;
    END//
    --�f���~�^���Z�~�R�����i�f�t�H���g�j������������
    delimiter ;
    --�X�g�A�h�v���V�[�W�����s
    call sp_hoge(1);
    12.2. Control Flow Functions
    CASE value WHEN [compare_value] THEN result [WHEN [compare_value] THEN result ...] [ELSE result] END
    CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE result] END
    The first version returns the result where value=compare_value. The second version returns the result for the first condition that is true. If there was no matching result value, the result after ELSE is returned, or NULL if there is no ELSE part.
    mysql> SELECT CASE 1 WHEN 1 THEN 'one'
    -> WHEN 2 THEN 'two' ELSE 'more' END;
    -> 'one'
    mysql> SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;
    -> 'true'
    mysql> SELECT CASE BINARY 'B'
    -> WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;
    -> NULL
    The default return type of a CASE expression is the compatible aggregated type of all return values, but also depends on the context in which it is used. If used in a string context, the result is returned as a string. If used in a numeric context, then the result is returned as a decimal, real, or integer value.
    Note: The syntax of the CASE expression shown here differs slightly from that of the SQL CASE statement described in Section 17.2.10.2, �gCASE Statement�h, for use inside stored routines. The CASE statement cannot have an ELSE NULL clause, and it is terminated with END CASE instead of END.
    IF(expr1,expr2,expr3)
    If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns expr2; otherwise it returns expr3. IF() returns a numeric or string value, depending on the context in which it is used.
    mysql> SELECT IF(1>2,2,3);
    -> 3
    mysql> SELECT IF(1<2,'yes','no');
    -> 'yes'
    mysql> SELECT IF(STRCMP('test','test1'),'no','yes');
    -> 'no'
    If only one of expr2 or expr3 is explicitly NULL, the result type of the IF() function is the type of the non-NULL expression.
    expr1 is evaluated as an integer value, which means that if you are testing floating-point or string values, you should do so using a comparison operation.
    mysql> SELECT IF(0.1,1,0);
    -> 0
    mysql> SELECT IF(0.1<>0,1,0);
    -> 1
    In the first case shown, IF(0.1) returns 0 because 0.1 is converted to an integer value, resulting in a test of IF(0). This may not be what you expect. In the second case, the comparison tests the original floating-point value to see whether it is non-zero. The result of the comparison is used as an integer.
    The default return type of IF() (which may matter when it is stored into a temporary table) is calculated as follows:
    Expression Return Value
    expr2 or expr3 returns a string string
    expr2 or expr3 returns a floating-point value floating-point
    expr2 or expr3 returns an integer integer
    If expr2 and expr3 are both strings, the result is case sensitive if either string is case sensitive.
    Note: There is also an IF statement, which differs from the IF() function described here. See Section 17.2.10.1, �gIF Statement�h.
    IFNULL(expr1,expr2)
    If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. IFNULL() returns a numeric or string value, depending on the context in which it is used.
    mysql> SELECT IFNULL(1,0);
    -> 1
    mysql> SELECT IFNULL(NULL,10);
    -> 10
    mysql> SELECT IFNULL(1/0,10);
    -> 10
    mysql> SELECT IFNULL(1/0,'yes');
    -> 'yes'
    The default result value of IFNULL(expr1,expr2) is the more �ggeneral�h of the two expressions, in the order STRING, REAL, or INTEGER. Consider the case of a table based on expressions or where MySQL must internally store a value returned by IFNULL() in a temporary table:
    mysql> CREATE TABLE tmp SELECT IFNULL(1,'test') AS test;
    mysql> DESCRIBE tmp;
    -------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    -------------------------------------------+
    | test | char(4) | | | | |
    -------------------------------------------+
    In this example, the type of the test column is CHAR(4).
    NULLIF(expr1,expr2)
    Returns NULL if expr1 = expr2 is true, otherwise returns expr1. This is the same as CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END.
    mysql> SELECT NULLIF(1,1);
    -> NULL
    mysql> SELECT NULLIF(1,2);
    -> 1
    Note that MySQL evaluates expr1 twice if the arguments are not equal.
    Previous / Next / Up / Table of Contents
    User Comments
    Posted by I W on July 12 2005 5:52pm [Delete] [Edit]
    Don't use IFNULL for comparisons (especially not for Joins)
    (example:
    select aa from a left join b ON IFNULL(a.col,1)=IFNULL(b.col,1)
    It's terrible slow (ran for days on two tables with approx 250k rows).
    Use <=> (NULL-safe comparison) instead. It did the same job in less than 15 minutes!!
    Posted by [name withheld] on November 10 2005 12:12am [Delete] [Edit]
    IFNULL is like oracle's NVL function (these should help people searching for NVL() ..)
    Posted by Philip Mak on May 26 2006 7:14am [Delete] [Edit]
    When using CASE, remember that NULL != NULL, so if you write "WHEN NULL", it will never match. (I guess you have to use IFNULL() instead...)
    Posted by Marc Grue on June 24 2006 2:03pm [Delete] [Edit]
    You can ORDER BY a dynamic column_name parameter using a CASE expression in the ORDER BY clause of the SELECT statement:
    CREATE PROCEDURE `orderby`(IN _orderby VARCHAR(50))
    BEGIN
    SELECT id, first_name, last_name, birthday
    FROM table
    ORDER BY
    -- numeric columns
    CASE _orderby WHEN 'id' THEN id END ASC,
    CASE orderby WHEN 'desc id' THEN id END DESC,
    -- string columns
    CASE orderby WHEN 'firstname' THEN first_name WHEN 'last_name' THEN last_name END ASC,
    CASE orderby WHEN 'descfirst_name' THEN first_name WHEN 'desc_last_name' THEN last_name END DESC,
    -- datetime columns
    CASE _orderby WHEN 'birthday' THEN birthday END ASC,
    CASE orderby WHEN 'desc birthday' THEN birthday END DESC;
    END
    Since the CASE expression returns the "compatible aggregated type of all return values", you need to isolate each column type in a separate CASE expression to get the desired result.
    If you mixed the columns like
    CASE _orderby
    WHEN 'id' THEN id
    WHEN 'first_name' THEN first_name
    ...etc...
    END ASC
    .. both the id and first_name would be returned as a string value, and ids would be sorted as a string to '1,12,2,24,5' and not as integers to '1,2,5,12,24'.
    Note that you don't need a "ELSE null" in the CASE expressions, since the CASE expression automatically returns null if there's no match. In that case, you get a "null ASC" in your ORDER BY clause which doesn't affect the sort order. If for instance orderby is 'descfirst_name', the ORDER BY clause evaluates to:
    ORDER BY null ASC, null DESC, null ASC, first_name DESC, null ASC, null DESC
    Effectively the same as "ORDER BY first_name DESC". You could even add a new set of CASE expressions for a second order column (or more..) if you like.
    Add your own comment.

    What is that post supposed to be?

  • How can i remove pictures from my droid turbo without having to use the touch screen on the phone at all?

    how can i remove pictures from my droid turbo without having to use the touch screen on the phone at all?  my screen is cracked and i am waiting on a replacement phone.  as far as i can tell in order to access the phone storage through my computer, i have to use the touchscreen to enable it so that the computer will see it as a camera.  I can't do that as the top half of the touschscreen is unresponsive.  any suggestions?  teaches me to use the backup services offered in the future, but i still need a short term solution for this time.

        I'm sorry to hear your screen is cracked spence425. I know its difficult to use the phone while its damaged. I'm happy you are receiving a replacement device. Have you saved any of your pictures and other data to the cloud? Here is a link about the cloud http://vz.to/1mF0GIx . Unfortunately, you will be unable to remove any data from the phone if the screen is unresponsive but if you are looking to transfer data to your new phone, it would have needed to be saved via the cloud first. Keep us posted.
    Kinquana_VZW
    Follow us on Twitter @vzwsupport

  • HT3819 Can I authorize mulitple apple ids on the same device so that what is purchased on either account will be loaded in both devices without having to use the same ID?

    Can I authorize mulitple apple ids on the same device so that what is purchased on either account will be loaded in both devices without having to use the same ID?
    My wife has a laptop and an iphone 4s, I have a laptop and and iphone 4s, our two sons have our old iphone 3s, we have an old laptop for our sons to use.  Our old iphones for our sons are deactivated as phones - so they are used as i-touches for songs, pictures and aps.  I want to use icloud (which I'm new to) to hopefully have all four iphones and all three computers stay synced with at least music - if not aps and pictures.  My wife has an apple ID and I have one.  I'd like to authorize all three laptops for both apple IDs so that we will still have our own accounts, but everything either of us buys will be automatically loaded into all three laptops and all four iphones.  Can this be done?
    Thanks,
    sstultzcostello

    Each person in your home can have their own Apple ID provided it is tied the their own separate email address.
    iTunes permits up to five authorized computers connected to a single Apple ID: iTunes Store- About authorization and deauthorization.
    For this all to work well, however, each user in your household should have a separate user account on the computer they commonly use.

  • How can I transfer my old information from my old iCloud account to my new one without resetting my phone and having to use my old account?

    How can I transfer my old information from my old iCloud account to my new one without resetting my phone and having to use my old account?

    What is wrong with your old iCloud account?

  • I recently bought a macbook pro and i made a new apple id. my last macbook had a different id as well and i was wondering if there's a way of transferring all my music from the other laptop to the new one without having to use my old apple id?

    i recently bought a macbook pro and i made a new apple id. my last macbook had a different id as well and i was wondering if there's a way of transferring all my music from the other laptop to the new one without having to use my old apple id? if it makes any type of difference i have an iphone 5 so i tried transfering the music but it only transfered certain things and not my entire album.

    Making a new Apple ID was the worst thing you could of done. This is very bad to do. Not sure why people do that. Your Apple ID is Your Apple ID. You only need one and it is best to only have one Apple ID for all apple devices.
    Sorry I don't have any suggestions for you.

  • Is there any way to get around having to use iDVD to burn DVD?

    Is there any way to get around having to use iDVD to export FCE to DVD?
    I've been trying to burn a FCE2 sequence to DVD. A friend of mine told me all I had to do was put a blank DVD in, click on the icon on the desk top, export the sequence to Quicktime and drag the QT sequennce into the DVD icon and click burn.
    Well something happened! But there's nothing on the DVD!! What am I doing wrong? I loathe iDVD. i don't want to author. I just want to burn the project on a DVD. Please advise. Thanks.
    Chuck
    iMAC 1.25 GHz PowerPC G4 Mac OS X (10.3.1)
    iMAC 1.25 GHz PowerPC G4   Mac OS X (10.3.1)  

    If you export a sequence at full resolution to can burn it onto a DVD as a data DVD, but this is for transportation purposes only. At full resolution the DVD, especially as it fills up, will not have sufficient throughput to sustain good playback of the material. That's why the material is encoded into MPEG-2 for DVD authoring. If you want to make a DVD for set-top playback it has to be authored to include the DVD format structure. There is no way around that. If you don't like iDVD, take a look at Final Cut Studio, you might prefer DVD Studio Pro. Or you might what to look at Roxio's Toast. It has basic authoring capabilities. Personally I don't think direct playback hardware solutions (except for seriously expensive ones) produce acceptable quality, but that's just me.

Maybe you are looking for