PreparedStatements and MySQL Connector/J

Hi All,
I was wondering what is the exact SQL statement that is passed to MySQL server when we use PreparedStatements. I was trying using MySQL Connector/J, type4 driver. I tried with a simple servlet
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException   {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<body>");
        out.println("<head>");
          try {
               Class.forName("com.mysql.jdbc.Driver");
               Connection con=DriverManager.getConnection("jdbc:mysql://localhost/mydb?user=root","root","");
               //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               //Connection con=DriverManager.getConnection("jdbc:odbc:test");
               PreparedStatement pst=con.prepareStatement("select * from AS_ITM where ID_ITM=?");
               out.println("PreparedStatement = "+pst);
               out.println("<br>");
               pst.setString(1, "10");
               out.println("PreparedStatement = "+pst);
               //ResultSet rs=pst.executeQuery();
               con.close();
          }catch(Exception e){
               out.println(e);
        out.println("</head>");
        out.println("<body>");
        out.println("</body>");
        out.println("</html>");
Here I am printing PreparedStatement  object's generated SQL twice and not even executing the query.
And the result is:
PreparedStatement = com.mysql.jdbc.PreparedStatement@19f3736: select * from AS_ITM where ID_ITM=** NOT SPECIFIED **
PreparedStatement = com.mysql.jdbc.PreparedStatement@19f3736: select * from AS_ITM where ID_ITM='10'
See second statement? I have not even sent it to the server.
So is this jdbc driver preparing a simple Statement before it is sent to MySQL server?
Is it what a jdbc driver is supposed to do? So then whats the use of PreparedStatement?Thanks,
Kishor

Hi,
Just exactly what a JDBC driver is supposed to do with a PreparedStatement is not specified in JDBC I believe. I think they only requirement is that a PreparedStatement should be able to insert the various data types correctly into an SQL string.
I am fully aware that PreparedStatements should also be able to give a better performance, for instance by only sending the parameters when you use it the second time, and not the whole the SQL. But I think this is up to the database and driver implementation to decide whether to do this, and how.
Remember, the JDBC driver may be sending other information across to the database than the SQL. We can't see that from looking at the PreparedStatement only. You would have to use a network packet sniffer to see all data exchanged between the driver and the database
-Jakob Jenkov

Similar Messages

  • Problems with PreparedStatement and MySQL selecting bytes

    Hi,
    i have a problem trying to select information when the "select" has a byte restrict.
    The table in database is:
    CREATE TABLE `positions` (
    `PKID` int(10) unsigned NOT NULL auto_increment,
    `POSCODE` varbinary(30) NOT NULL,
    `ISWTURN` binary(1) NOT NULL,
    `QTT_GAMES` int(10) unsigned NOT NULL default '1',
    PRIMARY KEY (`PKID`),
    UNIQUE KEY `UNIQ_POS` (`POSCODE`,`ISWTURN`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    And the test code to get the qtt_games is :
    conn = DriverManager.getConnection (url,user,pwd);
    byte bcode[] = poscode.getByteArrayCode();
    // bcode is inserted ok in another preparedstatement...
    String query = "SELECT qtt_games FROM positions "+
         "WHERE poscode=? and iswturn=?";
    PreparedStatement pstmt = conn.prepareStatement(query);
    pstmt.setBytes (1,bcode);
    pstmt.setByte (2,poscode.getIsWhiteTurn()); //it returns a byte
    ResultSet rs = pstmt.executeQuery (query);
    When pstmt.executeQuery is reached, it's thrown the exception:
    com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=? and iswturn=?' at line 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3099)
    at com.mysql.jdbc.Statement.execute(Statement.java:695)
    at app.server.bbdd.MYSQLBDManager.getGamesBasicInfo(MYSQLBDManager.java:942)
    at app.server.bbdd.MYSQLBDManager.main(MYSQLBDManager.java:1068)
    Can anybody tell me what's wrong?? I think the query is ok, but don't know what's happening with this...
    Lots of thanks.

    Don't cross-post, it's considered rude:
    http://forum.java.sun.com/thread.jspa?threadID=5122604&messageID=9430056#9430056
    http://forum.java.sun.com/thread.jspa?threadID=5122603&messageID=9430050#9430050
    One to a customer, please.
    %

  • Sun Application Server 8.x and MySql Connector 3.1 hangup problem

    Hello,
    I have several applications using com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource connection pools within SJAS 8.1 and 8.2. After a longer time of inactivity, the pool does not give me a connection anymore nor throws an exception. The server hangs endlessly and after several minutes other applications which aren't using DB access at all do not respond anymore as well.
    Does anybody have the same problem and found a solution?
    Thanks,
    marc.

    found it:
    http://forum.java.sun.com/thread.jspa?forumID=136&threadID=583959

  • MySQL connector between 10.4.8 Server Tomcat install and MAMP mySQL

    Hi all
    I was wondering if anyone has linked the OS X Server installed tomcat with mysql using the mysql java connector 5.0.4.
    We're hoping to use mamp as the apache and mysql base for our sites over the built in apache server, but know are stumbling on getting our MAMP apache/mysql talking with the OS X tomcat.
    Has anyone out there already done this - or can point to an uptodate walkthrough?
    Many thanks for any assistance!
    JT

    No docs that I am aware of but you do need to have a valid driver and DSN for the code you're using.
    You can find examples of code if you google it, it would be the same config as used with apache/tomcat/mysql.

  • How to include the mysql-connector in a simple .jar file

    Well I started up with java again. Just messing around. This project I'm making now is just plain simple, I have a program thats going to read a table in a database from a server I have here at home. It works fine if I do like this: java javafil to run the file, it reads from the database fine.
    But when I made a .jar file out of it using this command: jar cmf manifest.txt javafile.jar *.class
    It won't connect to the database. Or it doesn't print out the rows in the table. So I thought I have to include the mysql-connector with the .jar.
    manifest.txt
    Main-Class: javafile
    Now what is an easy way to do this?
    This program is also going to be run from a computer that might not have the mysql-connector installed on the computer. Like a friend of mine wants to connect to the database and read it.
    I've tried to google "mysql connector in a .jar file" but I get tons of informations about the mysql-connector.jar instead of what I'm looking for.
    Thanks,
    Torbj�rn Svae
    Edited by: LordSvae on 19.jun.2008 14:52

    LordSvae wrote:
    Yeah but the other computer might not have that connector file on their computer. So is there like I way I can use it when it is in the .jar file? Thats kinda what I wanted. You cannot include another JAR in a JAR file. You however can extract it and put the classes in your JAR. Verify the license agreement if it is allowed. Although this is considered as a bad practice (poor upgradebility and maintainability).
    If you don't want to use the -cp parameter, then use the class-path entry of the manifest.mf of your JAR. You can also write a batch file with the whole JAR -cp command in a single line and run the batch file instead.
    Pluss, even though I have the right classpath in the environment variables set, it doesn't work for me either. So I guess it doesn't load the connector when running the .jar file.The classpath environment variable has nothing to do with running JAR's. Forget about it and use the -cp or -classpath parameter.

  • Using mysql-connector-java-5.0.5 from oracle's java procedure.

    I need to write the java procedure in Oracle, which will get connection to mySQL server and put some data into it. I am using official mysql-connector-java-5.0.5 driver for this job. Java class for this job work well outside the Oracle. The problem is:
    When I try to import jar file of mysql connectior it fail son resolving inside the Oracle db. How can I get access to mysql from Oracle?

    Thanks for this quick reply!!
    --When adding a connection and clicking 'Test' in the end of the wizard or when right-click on the connection and click 'connect'.
    Also, I've just noticed this: when I start IDE using jdev.exe I'm getting:
    java.lang.NullPointerException at oracle.jdevimpl.cm.dt.DatabaseAddin._registerIDEObjects(DatabaseAddin.java:353)
    at oracle.jdevimpl.cm.dt.DatabaseAddin.initialize(DatabaseAddin.java:155
    at oracle.ideimpl.extension.AddinManagerImpl.initializeAddin(AddinManage
    rImpl.java:425)
    at oracle.ideimpl.extension.AddinManagerImpl.initializeAddins(AddinManag
    erImpl.java:240)
    at oracle.ideimpl.extension.AddinManagerImpl.initProductAndUserAddins(Ad
    dinManagerImpl.java:154)
    at oracle.ide.IdeCore.initProductAndUserAddins(IdeCore.java:1431)
    at oracle.ide.IdeCore.startupImpl(IdeCore.java:1196)
    at oracle.ide.Ide.startup(Ide.java:674)
    at oracle.ideimpl.Main.start(Main.java:49)
    at oracle.ideimpl.Main.main(Main.java:25)
    Does not look right to me.
    I've never tried to add a DB connection under this IDE installation earlier.
    Just yeasterday I've created a project with some DB related (mySQL and Hibernate) libraries, although it compiled fine.

  • Java\jdk1.6.0_02\jre\lib\ext\mysql-connector-java-5.1.16-bin.jar was unexp

    Hello, please i am new to Jdeveloper and weblogic servers and i developed an application using jdeveloper and when i try to run the application it brings up this error message
    "*** Using HTTP port 7101 ***
    *** Using SSL port 7102 ***
    C:\Users\Lucky\AppData\Roaming\JDeveloper\system11.1.2.3.39.62.76.1\DefaultDomain\bin\startWebLogic.cmd
    [waiting for the server to complete its initialization...]
    \Java\jdk1.6.0_02\jre\lib\ext\mysql-connector-java-5.1.16-bin.jar was unexpected at this time.
    Process exited."
    I tried deleting the jdk1.6.6.0_02 and tried it again but it still did not run, I also uninstalled the JDeveloper and weblogic server and reinstalled them but the error message still pops up. Please i need help to fix this.
    Thanks.
    Edited by: Chinedu on Feb 21, 2013 8:48 AM

    Andrew,
    Thanks for the lightning response... but the problem has been solved.
    I rebooted again, and installed again (didn't download again because the filesize checked out) and now it works fine, and I'm none the wiser as to the root cause of the problem, except that rt.jar has magically appeared:
    C:\Users\Administrator>dir "C:\Program Files\Java\jre6\lib\*.jar"
    Volume in drive C has no label.
    Volume Serial Number is 00AC-1BC7
    Directory of C:\Program Files\Java\jre6\lib
    08/11/2009  06:38 PM         6,685,813 charsets.jar
    08/11/2009  06:38 PM         2,989,538 deploy.jar
    08/11/2009  06:38 PM           716,841 javaws.jar
    08/11/2009  06:38 PM            88,256 jce.jar
    08/11/2009  06:38 PM           558,189 jsse.jar
    08/11/2009  06:38 PM               382 management-agent.jar
    08/11/2009  06:38 PM         1,704,664 plugin.jar
    08/11/2009  06:38 PM         1,115,985 resources.jar
    08/11/2009  06:38 PM        44,295,255 rt.jar                             <<<<<<<<<<<<<<<<<<
                   9 File(s)     58,154,923 bytes
                   0 Dir(s)  115,454,173,184 bytes freeSOOOO... I presume that the installer failed on rt.jar, probably because something (something in my start-up, I suppose) was using the JRE while the instal was running... but I didn't do anything different the second time (to the best of my knowledge).
    Thanks anyways... My hair (what's left of it) greatly appreciates your time.
    Cheers. Keith.

  • How to handle blob data with java and mysql and hibernate

    Dear all,
    I am using java 1.6 and mysql 5.5 and hibernate 3.0 . Some time i use blob data type . Earlier my project's data base was oracle 10g but now i am converting it to Mysql and now i am facing problem to save and fetch blob data to mysql database . Can anybody give me the source code for blob handling with java+Mysql+Hibernate
    now my code is :--
    ==================================================
    *.hbm.xml :--
    <property name="image" column="IMAGE" type="com.shrisure.server.usertype.BinaryBlobType" insert="true" update="true" lazy="false"/>
    ===================================================
    *.java :--
    package com.shrisure.server.usertype;
    import java.io.OutputStream;
    import java.io.Serializable;
    import java.sql.Blob;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Types;
    import javax.naming.InitialContext;
    import javax.sql.DataSource;
    import oracle.sql.BLOB;
    import org.hibernate.HibernateException;
    import org.hibernate.usertype.UserType;
    import org.jboss.resource.adapter.jdbc.WrappedConnection;
    import com.google.gwt.user.client.rpc.IsSerializable;
    public class BinaryBlobType implements UserType, java.io.Serializable, IsSerializable {
    private static final long serialVersionUID = 1111222233331231L;
    public int[] sqlTypes() {
    return new int[] { Types.BLOB };
    public Class returnedClass() {
    return byte[].class;
    public boolean equals(Object x, Object y) {
    return (x == y) || (x != null && y != null && java.util.Arrays.equals((byte[]) x, (byte[]) y));
    public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    BLOB tempBlob = null;
    WrappedConnection wc = null;
    try {
    if (value != null) {
    Connection oracleConnection = st.getConnection();
    if (oracleConnection instanceof oracle.jdbc.driver.OracleConnection) {
    tempBlob = BLOB.createTemporary(oracleConnection, true, BLOB.DURATION_SESSION);
    if (oracleConnection instanceof org.jboss.resource.adapter.jdbc.WrappedConnection) {
    InitialContext ctx = new InitialContext();
    DataSource dataSource = (DataSource) ctx.lookup("java:/DefaultDS");
    Connection dsConn = dataSource.getConnection();
    wc = (WrappedConnection) dsConn;
    // with getUnderlying connection method , cast it to Oracle
    // Connection
    oracleConnection = wc.getUnderlyingConnection();
    tempBlob = BLOB.createTemporary(oracleConnection, true, BLOB.DURATION_SESSION);
    tempBlob.open(BLOB.MODE_READWRITE);
    OutputStream tempBlobWriter = tempBlob.getBinaryOutputStream();// setBinaryStream(1);
    tempBlobWriter.write((byte[]) value);
    tempBlobWriter.flush();
    tempBlobWriter.close();
    tempBlob.close();
    st.setBlob(index, tempBlob);
    } else {
    st.setBlob(index, BLOB.empty_lob());
    } catch (Exception exp) {
    if (tempBlob != null) {
    tempBlob.freeTemporary();
    exp.printStackTrace();
    st.setBlob(index, BLOB.empty_lob());
    // throw new RuntimeException();
    } finally {
    if (wc != null) {
    wc.close();
    public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
    final Blob blob = rs.getBlob(names[0]);
    return blob != null ? blob.getBytes(1, (int) blob.length()) : null;
    public Object deepCopy(Object value) {
    if (value == null)
    return null;
    byte[] bytes = (byte[]) value;
    byte[] result = new byte[bytes.length];
    System.arraycopy(bytes, 0, result, 0, bytes.length);
    return result;
    public boolean isMutable() {
    return true;
    public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
    return assemble(arg0, arg1);
    public Serializable disassemble(Object arg0) throws HibernateException {
    return disassemble(arg0);
    public int hashCode(Object arg0) throws HibernateException {
    return hashCode();
    public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
    return replace(arg0, arg1, arg2);
    =================================================================
    can anyone give me the source code for this BinaryBlobType.java according to mysql blob handling ..

    Moderator action: crosspost deleted.

  • Mysql connector & ssl

    Hi,
    I have enabled ssl on my mysql server and am using useSSL=true&requireSSL=true in my jdbc connector url.
    I am getting the following error:
    The root cause was that: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** com.mysql.jdbc.CommunicationsException MESSAGE: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** javax.net.ssl.SSLHandshakeException MESSAGE: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target STACKTRACE: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1591)  at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187) at
    If anyone had any success connecting to mysql via ssl I would appreciate any help.
    Thanks!

    I used the mysql odbc connector with the certificate and it worked fine so
    the problem is not the certificate.
    2009/4/8 Alexei Yakovenko <[email protected]>
    drieh,
    >
    A new message was posted in the thread "mysql connector &amp; ssl":
    >
    http://forums.adobe.com/message/1877560#1877560
    >
    Author  : Alexei Yakovenko
    Email   : [email protected]
    Profile : http://forums.adobe.com/people/injun%20%5B576871%5D
    >
    Message:

  • JSTL - MySQL Connector problem

    Hello! I need your help. I don't actually know the reason, but *<sql:query>* doesn't work properly.
    So I have such a code:
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql_rt" %>
    <sql:setDataSource var="datasource"
    driver="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/publish"
    user="root" password="root"/>
    <sql:query var="books" dataSource="${datasource}">
    SELECT id, title, price FROM book
    </sql:query>
    <html>
    <head>
    <title>A First JSP Database</title
    </head>
    <body>
    <table border="1">
    <tr>
    <td>id</td><td>title</td><td>price</td>
    </tr>
    <c:forEach items="${books.rows}" var="row">
    <tr>
    <td><c:out value="${row.id}" /></td>
    <td><c:out value="${row.title}" /></td>
    <td><c:out value="${row.price}" /></td>
    </tr>
    </c:forEach>
    </table>
    </body>
    </html>The error I get when calling http://localhost:8080/DataAccess/bookList.jsp
    org.apache.jasper.JasperException: Exception in JSP: /bookList.jsp:7
    4:                  driver="com.mysql.jdbc.Driver"
    5:                     url="jdbc:mysql://localhost:3306/publish"
    6:                    user="root" password="root"/>
    7: <sql:query var="books" dataSource="${datasource}">
    8:   SELECT id, title, price FROM book
    9: </sql:query>
    10: <html>May be the reason is that the subfolder WEB-INF is badly configured.
    I have such subfolders in WEB-INF:
    */lib*
    jaxen-full.jar
    jdbc2_0-stdext.jar
    jstl.jar
    mysql-connector-java-3.0.9-stable-bin.jar
    saxpath.jar
    standard.jar
    xalan.jar
    xercesImpl.jar
    xml-apis.jar
    */tld*
    c-rt.tld
    c.tld
    fmt-rt.tld
    fmt.tld
    sql-rt.tld
    sql.tld
    x-rt.tld
    x.tldThe question is what is configured or done incorrectly? I am not quite familiar with JSP and JSTL. Thank you for any help.
    P.S I have already used MySQL. So it is set and configured as it is needed to be.

    ThomYork
    It didn't help.
    Just in case, I run tomcat 5.5.27-2 on Arch Linux; MySQL 5.0.77; Apache 2.2.11
    I tried to put mysql-connector-java-3.0.9-stable-bin.jar into
    /opt/tomcat/server/lib
    /opt/tomcat/shared/lib
    It didn't help.
    bandarurm
    After some manipulation i get such an error in my script:
    *exception*
    {noformat}org.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused"
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    {noformat}
    *root cause*
    {noformat}javax.servlet.ServletException: Unable to get connection, DataSource invalid: "Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused"
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
         org.apache.jsp.bookList_jsp._jspService(bookList_jsp.java:89)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    {noformat}
    *root cause*
    {noformat}javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused"
         org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:276)
         org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:159)
         org.apache.jsp.bookList_jsp._jspx_meth_sql_005fquery_005f0(bookList_jsp.java:130)
         org.apache.jsp.bookList_jsp._jspService(bookList_jsp.java:66)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    {noformat}
    dsdsf
    I tried this. I downloaded the example with the source and WEB-INF directory. It doesn't work.
    Here is an error:
    *exception*
    {noformat}org.apache.jasper.JasperException: javax.servlet.jsp.JspTagException: In <driver>, invalid driver class name: "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    {noformat}
    *root cause*
    {noformat}javax.servlet.ServletException: javax.servlet.jsp.JspTagException: In <driver>, invalid driver class name: "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:837)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
         org.apache.jsp.executeQuery_005fJstlSqlTag_jsp._jspService(executeQuery_005fJstlSqlTag_jsp.java:116)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    {noformat}
    *root cause*
    {noformat}java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
         java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
         java.lang.Class.forName0(Native Method)
         java.lang.Class.forName(Class.java:264)
         org.apache.taglibs.standard.tag.common.sql.DataSourceWrapper.setDriverClassName(DataSourceWrapper.java:46)
         org.apache.taglibs.standard.tag.common.sql.SetDataSourceTagSupport.doStartTag(SetDataSourceTagSupport.java:102)
         org.apache.taglibs.standard.tag.el.sql.SetDataSourceTag.doStartTag(SetDataSourceTag.java:67)
         org.apache.jsp.executeQuery_005fJstlSqlTag_jsp._jspx_meth_sql_005fsetDataSource_005f0(executeQuery_005fJstlSqlTag_jsp.java:137)
         org.apache.jsp.executeQuery_005fJstlSqlTag_jsp._jspService(executeQuery_005fJstlSqlTag_jsp.java:88)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    {noformat}Nothing with sql query works. So it seems that the problem is in tomcat's configuration.

  • Help registering driver mysql-connector-j

    Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    Hello Everyone, I keep on getting a java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    exception when I attempt to register the mysql-connector-j.
    I'm just using the code from it's documentation:
    public class LoadDriver {
    public static void main(String[] args) {
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch (Exception ex) {
    System.out.println(ex);
    I have a CLASSPATH 'user' variable containing...
    C:\JavaStuff; C:\mysql-connector-java-3.1.1-alpha\mysql-connector-java-3.1.1-alpha-bin.jar
    Where JavaStuff is the location of the LoadDriver class. I have to fix this thing as soon as possible as I'm currently working on a project. Much help will be apprecieated. I have a feeling it may be somthing to do with the classpath!

    It is the classpath.
    Do you really have a space after c:\javastuff? (You shouldn't.)
    Is that really the path to the jar file? And does that jar file really contain the driver class?
    I assume you are asking in the context of a Java application, which uses the CLASSPATH environment variable. Other possibilities (servlets, applets, executable jar files) have other ways of finding classes.

  • JDBC MySQL Connector/J problems when using in applets

    I wrote a piece of code which uses the MySQL Connector/J which worked in a normal shell application but when used in an applet it just didnt print anything. The code is:
    import java.net.*;
    import java.sql.*;
    class DB {
    static Connection c;
    static Statement stmt;
    static ResultSet to;
    public static String[] getUsers() {
         String str[] = new String[100];
         try {
              Class.forName("com.mysql.jdbc.Driver").newInstance();
         catch (Exception E) {}
         try {
              c = DriverManager.getConnection("jdbc:mysql://localhost/PROGRAM?user=blah&password=blah");
              stmt = c.createStatement();
              to = stmt.executeQuery("SELECT usr_user FROM usr");
              for(int i=0; to.next(); i++) str[i] = to.getString(1);
         catch (SQLException E) {}
         return str;
    Is there a problem accessing a MySQL Database via an applet

    Applet runs out of a sandbox, if you print the exception, you'll see that you have run into security access violation:
    catch (SQLException E) {
    E.printStackTrace();
    }This will tell you why your applet didn't print anything. Just a firendly advice, never try to catch something and don't display what was caught.
    ;o)
    V.V.
    PS: To solve, your problem, you can either sign the applet or use a policy file to grant the applet the required access right.

  • JDBC and MySQL connectivity problem

    The code i hav attached generates Connectivity exception.. the prob is with the part in bold.. can anyone help
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    public class testconn {
      public static void main(String args[]) {
        Connection con = null;
                String serverName = "localhost:8080";
            String mydatabase = "imagedb";
            String url = "jdbc:mysql://" + serverName +  "/" + mydatabase; // a JDBC url
            String username = "am";
            String password = "ta";
        try {
          Class.forName("com.mysql.jdbc.Driver");
         con= DriverManager.getConnection(url, username, password);
          if(!con.isClosed())
            System.out.println("Successfully connected to " +
              "MySQL server using TCP/IP...");
        } catch(Exception e) {
          System.err.println("Exception: " + e);
        } finally {
          try {
            if(con != null)
              con.close();
          } catch(SQLException e) {}
    }

    I had such issue too, and I fixed it by adding in the environment variables the CLASSPATH entry that pointed to all the directories containing the .jar needed for the applications.
    for example I used jodbc folder to connect mysql database (I installed last version and I got same issue than yours and it seems to be a 'connector' issue, exactly the same issue than yours) I got something like
    CLASSPATH=my root dir/the java dir/the lib dir/jodbc;my root dir/the java dir/other important libs containing .jar files;
    This is what I got for the issue, still working around (at the level of mysql all is ok, ...)
    Microsoft Windows XP [version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    C:\Documents and Settings\Hurukan>java ConnectJODBC brol
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at ConnectJODBC.main(ConnectJODBC.java:108)
    [exception] -- la valeur de 'con' est nulle (DriverManager � retourn� une valeur
    nulle)
    C:\Documents and Settings\Hurukan>set
    APPDATA=C:\Documents and Settings\Hurukan\Application Data
    CLASSPATH=c:\Program Files\Java\jdk1.5.0_06\lib;c:\Program Files\Java\jdk1.5.0_06\dev;\c:\Program Files\Java\jdk1.5.0_06\lib\jodbc;
    Here is the code that generated this exception
    String dburl="jdbc:mysql://127.0.0.1/nosdisques"; // should be next passed by command line
    String password="**scrambled**";
    String username="**scrambled**";
    Connection con=null;
    Statement stmt=null;
    ResultSet res=null;
    String requete="";
    String strToWrite="";
    // Connexion � la base de donn�e
    // Won't work with mysql 5.0.18, mysql connector 3.51.12 is installed [???]
    // Previous tests with 5.0.18 were running good, that has started with the last os restoration (and the connector was different of course...)
    // tried to retreive older version of the mysql connector
    try
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con=DriverManager.getConnection(dburl,username,password);
    System.out.println("Nous sommes connect\u201as \u2026 la base " + con.getCatalog());
    catch(SQLException sqlex)
    System.out.println("[sqlexception]\n");
    System.exit(3);
    catch(Exception ex)
    ex.printStackTrace();
    if(con == null)
    System.out.println("[exception] -- la valeur de 'con' est nulle (DriverManager \u2026 retourn\u201a une valeur nulle)\n");
    System.exit(4);
    System.out.println("Impossible to join database, access denied\n");
    System.out.println("Verify settings (mysqld or firewall)\n"); System.exit(2);
    Maybe the drivers used (last one: connector/j 3.1.12). The .jar file is in the %classpath% directory c:\Program Files\Java\jdk1.5.0_06\lib.
    Can't really understand why this code won't run anymore, ...
    I took a look on the other computer where the same code is running ok.
    These are the differences:
    mysql server is 5.0.18 on the other computer the version is 3.23.41
    mysql connector is 3.51.12 on the other computer the version is 3.0.10
    access rights are the same because the database is the dumped one from 3.23.41 to 5.0.18, and I'm quite good with the dbms management (I'm IT developper in fact, trying to take over java technology ;) )
    in this case this is not a sql error but java error.
    the jar file is set to the %classpath% folder on both computers
    I copied the jar from the other computer, removing the new .jar file and... it failed, exactly the same issue
    Still working around, ...
    Dimitri

  • Wrong use of Java and Mysql?

    I currently have a dedicated database server which runs MySQL. On the MySQL server I have 15 tables with the InnoDB engine.
    These tables all have a column called "last_sync". Whenever a tablerow is updated by a java client, the "last_sync" column is refreshed.
    Other java clients will query these tables with a query that looks something like this
    "Select count(*) from table where last_sync > (currenttime-5 seconds) and last_sync <= (currenttime)"
    So much for the background info. To stresstest my server, and see how much queries per second he can handle,
    I installed Super Smack (http://vegan.net/tony/supersmack/). Super smack is a stresstest tool which can be given 2 start-up parameters.
    These parameters say how many clients/threads should connect and how many times the query should be ran. When installed it
    is possible to alter the stress query by editting the "select-key.smack" file. I did so and placed a query that is equal to the above statement.
    Super-smack (as well as MySQL Administrator and Innotop) tells me that it can execute 50K queries per second when I use a single connection.
    When I use two connections I get roughly 88K. This is logical since my server is a dual-core machine. I run super smack on my DB server.
    Now, whenever I try to stresstest my server with a java written test, I can barely get to 10k queries per second on a single connection.
    The app is being runned on the DB server as well. Furthermore when I add another connection, the limit stays at 10k queries.
    When monitoring the connection threads with MySQL Administrator the connection threads
    are often "sleeping" while, when I run the SuperSmack test they are constantly in use.
    Another detail, the connection threads also gives info what it's doing ("Executing query", "Writing to net" etc.). I occasionally see "Rollback", which is strange
    since my stress query is not failing in my stress application.
    To make this complete, I've uploaded my little test along with the SQL creation code to the following URL: HERE
    It should work straight out of the box. Naturally the table creation query should be ran and the connection settings specified in the java file.
    Basically the one thing I cannot understand is why supersmack runs a factor 5-8 faster than my java test while they are
    using the exact same table and are executed on the exact same machine. This however limits out the possibility of it being a database config setting.
    Im personally guessing im incorrectly using transactions or the MySQL connector/j is giving problems.
    I understand this might take some effort, so i'll try to add more dukes than a regular post.
    -Edit. Was under the assumption that you could add more than 10 duke points.
    Thanks in advance
    Edited by: killingdjef on Mar 25, 2009 6:52 AM
    Edited by: killingdjef on Mar 25, 2009 10:28 AM

    killingdjef wrote:
    10K can be perfect, however, when I run Supersmack and see that my database server can handle 8 times more queries per second on the exact same table with the exact same query,
    I'm beginning to wonder if im doing something incorrect or if i'm missing something crucial.
    I have no clue whats a reasonable amount of queries per second is for a dedicated innodb server
    but based on the benchmark test im thinking I can squeeze out more.
    The stresstest isnt representational for a single client. Its merely a simulation how many clients could be served.
    The higher the queries per second, the more clients that can be served. Im trying to find out what the limit would be.I am quite aware of what impact means in terms of client processing. That however isn't the point. The point is that you intend to serve a market of some sort and support some reasonable growth. It is pointless to try to do more than that.
    If you have enough "clients" running directly against that database to generate 10k queries a second then your architecture (and thus design and implementation) is very likely flawed.
    For example
    1. What happens to all of those clients when the database goes down either accidently or on purpose?
    2. Those clients are hitting the database direct, and I don't see how you are going to get enough clients like that without internet consumers. And you absolutely do not want to expose the database that way.
    3. Conversely say you have a call center with 2000 support people, which is a huge call center. There is no way that number could generate even close to 10k a second.
    4. A comparable txn business model is credit card processing and a sustained speed like that would be sufficient to handle all of the credit card transaction business in the US during the peak xmas season. With extra left over.
    Not to mention that you didn't address the network problem at all. Note that the numbers I outlines above doesn't allow any bandwidth for the data to get into the server in the first place.
    And inserts will take more time than queries.
    But as I already said, if you are using transaction then that will have an impact. Connections/threads will as well.

  • Few question about Java and MySQL connection

    Hi!
    I have some problems with creating connection between Java and MySQL.
    I followed the restrictions in mysql-connector-java.jar' readme, I set the CLASSPATH :
    CLASSPATH=.;D:/mysql/mysql-connector-java.jar;
    I copied this jar file to the right place (descripted above), and I used the right steps to load it:
    Class.forName('com.mysql.jdbc.Driver"); and it throws a ClassNotFoundException
    Why? All the paths are correct, everything is on the right place.... I dont know why.
    When I installed the JBuilder8, and copied the jar file to JBuilder8/jdk4/jre/lib/ext it worked without any CLASSPATH in enviromental variables.
    If I want to run my program on machines where are not JBuilder, what should I do?
    Please help, if you can.
    Thanks,
    henpanta

    Yeah. So if I compiled my program with JBuilder to an .exe file, I cant run it on other machines, if the jar file isnt in the same place?
    If I tried your advice, java -classpath mymainclass I got the next message:
    main class not found. Believe me, its there. :(

Maybe you are looking for

  • Wireless Mouse and XOrg

    Hi guys, I have a wireless logitech mouse connected to my laptop via the PS2 port. Whenever I start Arch/XOrg, the mouse doesn't work at all. However, if I unplug the mouse and plug it straight back in it then works. I have tried with and without hot

  • Create a contract with its premise with a BAPI

    Hello People, My doubt is as follows: I need to create massive contracts in CRM '07 that replicates in IS-U, use the role to which he BAPI_BUSPROCESSND_CREATEMULTI step various parameters (see the final code), the problem lies in the allocation of th

  • How to shell script for noob? or Cryptography for someone who doesn't need.

    Hi, I've seen the need of automating some tasks in the Terminal and I believe using shell scripts is my solution, although I don't really even understand how they work. Instead of posting a full how-to here, I'd like to ask if anyone knows about good

  • I just got Apple TV today. Please help.

    I can't connect the Remote App to the Apple TV. I just wanted to stream from the phone to the device. My computer is not wireless. My apple tv sits next to my router. If I plug the router into the ATV it does see my computer itunes but then the ATV i

  • Best strategy to retrieve large amount of data with EJB ?

    Hi all I have an EJB 3 which is fronted by a Web Service. The EJB retrieves a large amount of objects (TaskList) and returns it to the client. @Stateless public List <TaskList> findByRole(String role){ List <TaskList> tasklist = em.createNamedQuery("