Java connect to mysql

hi,im new user here.....im also a new java user.......i've just learn how to connect java with mysql,so i download the driver MySQL Connector/J 5.0
after that,i mport the library to JBulider X.then i got error with my script.
package database;
import java.sql.*;
public class Mysql {
public static void main(String[] args) {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
catch (Exception e){
System.err.println("Error Loading driver :" + e.getMessage());
and then the error are :
java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Class.java:141)
     at database.Mysql.main(Mysql.java:19)
Exception in thread "main"
What is that meant ?please someone help me...i need a quick reply......thanxxxsss....

hello,all.........i just connected to the driver,but now another error come out
Error SQL Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect
STACKTRACE:
java.net.SocketException: java.net.ConnectException: Connection refused: connect
     at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
     at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
     at com.mysql.jdbc.Connection.createNewIO(Connection.java:2592)
     at com.mysql.jdbc.Connection.<init>(Connection.java:1509)
     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
     at java.sql.DriverManager.getConnection(DriverManager.java:512)
     at java.sql.DriverManager.getConnection(DriverManager.java:193)
     at database.Mysql.main(Mysql.java:28)
** END NESTED EXCEPTION **
wat is that mean ?
this is my script
package database;
import java.sql.*;
public class Mysql {
public static void main(String[] args) {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
System.out.println("Loading drivers........");
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Driver loaded !");
catch (Exception e){
System.err.println("Error Loading driver :" + e.getMessage());
try {
con = DriverManager.getConnection("jdbc:mysql://localhost/test_db?user=test_admin&password=1234");
stmt = con.createStatement();
rs = stmt.executeQuery("select * from `stock`");
ResultSetMetaData rsmd = rs.getMetaData();
int nColumn = rsmd.getColumnCount();
for(int i=1;i<=nColumn;i++){
System.out.print(rsmd.getColumnName(i) + " | ");
System.out.print("\n");
/*while(rs.next()){
System.out.println(rs.getLong(1) + "\t" + rs.getString(2) + "\t" + rs.getLong(3) + "\t" + rs.getString(4) + "\t"
+ rs.getDouble("price") + "\t" + rs.getInt("supplier") + "\t" + rs.getDate("buy_date"));
rs.close();
stmt.close();
con.close();
catch (SQLException e){
System.err.println("Error SQL " + e.getMessage());

Similar Messages

  • New to java connection with MySQL

    hello people,
    I have downloaded 'mysql-connector-java-5.0.3' and I have unzipped it in my E directory. I am using notepad to edit java. How should I set the Class path and make the connection . Please help
    Thanks in adance
    Kris

    after executing the following code
    import java.sql.*;
    public class conntest
         static Connection conn;
         public conntest()
         public static void main(String args[])
              try
                   Class.forName("com.mysql.jdbc.Driver").newInstance();
                   conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/kris?user=root");
              catch(Exception ex)
                   System.out.print("error"+ex.getMessage());
              try{
                   Statement s = conn.createStatement();
                         ResultSet rs = s.executeQuery("SELECT * FROM code");
                   while(rs.next())
                        System.out.println(rs.getString(1));
              catch(SQLException ex1)
                   System.out.println(ex1.getMessage());
    }it shows this as exception :"com.mysql.jdbc.Driver"
    why is that? I set the class path as : e:\mysql-connector-java-5.0.3\mysql-connector-java-5.0.3-bin.jar
    Thanks
    Kris

  • Java connection with mysql

    Anybody please help me:
    I creating java application that comunicate with the mysql database. I use JConnector and all work find.
    My problem is when i compile the program into JAR file and when i run it(double click the file), i saw my application but the connection with the mysql database is not successfull. i try to search from internet, and i found that i must put my JConnector inside the jdk1.3.1/jre/lib/ext.
    Once i put that the program can run and the connection is fine, but only if i run it from the dos by typing the command c:\java -jar turkeySystem.jar.
    So anybody can advise me, what should i do if i want to make my application run smoothly and connected with the database, without having the dos run at the background. (just double click the jar file).
    i don't have problem to run that if i using ms access as a database.
    Thank you in advanced.

    if it runs with "java -jar turkeySystem.jar." you have a valid manifest.mf in your jar. so it can basically be executed by double clicking it --- if the JDK is installed correctly. otherwise you need to change the datatype handling in windows by adding "java -jar %1" as the command for the file suffix ".jar". this is the case if you e.g. just copy your Java SDK folder to a computer and didn't install it with the windows exe java wizard.

  • Java Connector via MySQL [ Cannot Connect ]

    I downloaded the MySql connector and extracted the connector and placed it at this directory,
    C:\Program Files\Java\jdk1.5.0_06\jre\lib\ext
    I also set the classpath as such by adding
    ClassPath = .;C:\Program Files\Java\jdk1.5.0_06\jre\lib\ext\mysql-connector-java-3.1.12-bin.jar.Actually , I followed the tutorial at
    http://www.stardeveloper.com/articles/display.html?article=2003090201&page=4.
    I then executed this program below.
    import java.sql.*;
    public class Connect {
      public static void main(String args[]) {
        Connection con = null;
        try {
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         con = DriverManager.getConnection("jdbc:mysql:///enron", "root", "horizon");
          if(!con.isClosed())
            System.out.println("Successfully connected to MySQL server...");
        } catch(Exception e) {
          System.err.println("Captured Exception: " + e.getMessage());
        } finally {
          try {
            if(con != null)
              con.close();
          } catch(SQLException e) {}
    However i was unable to connect..This is wat happened as below..
    C:\>java Connect
    Captured Exception: Communications link failure due to underlying exception:
    ** BEGIN NESTED EXCEPTION **
    java.net.UnknownHostException
    MESSAGE: localhost: localhost
    STACKTRACE:
    java.net.UnknownHostException: localhost: localhost
            at java.net.InetAddress.getAllByName0(Unknown Source)
            at java.net.InetAddress.getAllByName0(Unknown Source)
            at java.net.InetAddress.getAllByName(Unknown Source)
            at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:137)
            at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
            at com.mysql.jdbc.Connection.createNewIO(Connection.java:2555)
            at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
            at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at Connect.main(Connect.java:7)
    ** END NESTED EXCEPTION **
    Last packet sent to the server was 31 ms ago.
    Any Help watsoever is greatly appreciated.
    Thanks in advance.
    Cheers.

    Hi thanks for the reply.
    Although , I am though a bit baffled by your reply.
    Where is it that you want me to add the URL.Not add the URL - change the one you have. Read the docs for the connector and follow that.
    And where else should i place that jar file.I put it in my CLASSPATH, close to where the source for my project is. (That means not in one place, but several places. I duplicate the JAR file for every app that needs it.)
    Cos I follow the tutorial at...
    http://www.stardeveloper.com/articles/display.html?art
    icle=2003090201&page=4.
    Unless You are saying that the above site is wrong..
    If thats the case, can you point out another
    alternative site which can guide me along .No time to read that site, nor do I have the interest.
    The Sun Java tutorial is sufficient for using JDBC. As far as how you package and deploy apps, that's another matter. You should be using the class name and URL that your JDBC driver docs suggest.
    %

  • How to Connect to Mysql databse from Java Studio Enterprise 8

    Hello everybody,
    I have a database in mysql in linux.I have downloaded Java Studio Enterprise 8.
    How is it possible to connect to mysql.
    Could you tell the procedure .., I would be really thankfull
    From
    Ranjitha Rao

    hi
    u can connect to Mysql with the following code
    Class.forName("com.mysql.jdbc.Driver");
                   String url1 = "jdbc:mysql://localhost/<database name>";
                   String user1 = "root";
                   String pass1 = "";
                   Connection con1=DriverManager.getConnection(url1, user1, pass1);

  • How to connect to mysql from java app

    hi
    please say the procedure for connecting to mysql database from java app.
    .) what should i give in environmental variables
    .)where can i find the driver class for the mysql
    .) syntax of the url
    eg:- DM.getConnection("jdbc:mysql:..............what comes here..............");

    You can also get connections from a DataSource. Simple example:
                MysqlDataSource msds = new MysqlDataSource();
                msds.setUrl("jdbc:mysql://127.0.0.1:3306/dbdame");
                msds.setUser("user");
                msds.setPassword("pass");
                Connection c = msds.getConnection();Explore your options and be sure to consider connection pooling.

  • Glassfish SQLException: Error in allocating a connection in MySQL

    Hi All,
    I have just installed the Bundled Netbeans 6.5, Glassfish v2 and v3 Prelude (not including MySQL) that runs on top of MySQL 5.1 (separate installation) on server A, in order to mirror another similar working installation (Bundled Netbeans 6.1, Glassfish v2 including MySQL 5.0) on server B. Both Windows XP servers have got identical setups in their respective C:\Program Files\glassfish-v2ur2\domains\domain1\config\domain.xml files. However, the following error was encountered when trying to deploy the same EnterpriseApplication on server A which had no such problem on server B:
    Glassfish Server Log
    Server: unknown
    RAR5099 : Wrong class name or classpath for Datasource Object
    java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
            at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1498)
            at com.sun.gjc.common.DataSourceObjectBuilder.getDataSourceObject(DataSourceObjectBuilder.java:251)
            at com.sun.gjc.common.DataSourceObjectBuilder.constructDataSourceObject(DataSourceObjectBuilder.java:106)
    RAR5038:Unexpected exception while creating resource for pool mysqlPool. Exception : Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
    RAR5117 : Failed to obtain/create connection from connection pool [ mysqlPool ]. Reason : Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
    RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource]
    Exception occured in J2EEC Phase
    com.sun.enterprise.deployment.backend.IASDeploymentException:
    Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
    Error Code: 0
            at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:305)
    EnterpriseApplication (EJB 3.0) Deployment output
    Deploying application in domain failed; Deployment Errorjava.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --
    Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
    Error Code: 0
    C:\Documents and Settings\Jack\EnterpriseApplication\EnterpriseApplicationBean-ejb\nbproject\build-impl.xml:400: The module has not been deployed.Even manually re-creating the same project (as opposed to getting a copy of the Netbeans project folder from server B) did not make any difference. Likewise, the following jdbc connection pool definition was added possibly by Netbeans from Server Database JDBC Connection Resource setting:
          <property name="URL" value="jdbc:mysql://localhost:3306/employeeDB"/>
          <property name="driverClass" value="com.mysql.jdbc.Driver"/>
          <property name="Password" value="abcdef"/>
          <property name="portNumber" value="3306"/>
          <property name="databaseName" value="employeeDB"/>
          <property name="serverName" value="localhost"/>
          <property name="User" value="applicationuser"/>Can anyone see where the problem lies?
    Any assistance would be much appreciated.
    Thanks in advance,
    Jack

    I'm new to Java and GlassFish and I get the same error message when trying to ping my created data pool for MySQL. Inside the NetBeans IDE running Java Swing Applications + MySQL connection via JDBC, it works fine (Classpath settings ok). I set the same path to the JVM settings in Glassfish but every time I try to ping it the mentioned error occurs. Any suggestions?

  • I can't connect to MySQL database from The JSP Standard Tag Library

    Hi All !
    I have a problem, please help me anybody !
    I don't connect to MySQL database from jsp page using JSTL tag but from servlet all work correctly. I set my path and put �mysql-connector-java-3.1.13-bin.jar� in ENVIRONMENT WinXP(classpath=C:\Java\jdk1.5.0_10\jre\lib\ext\mysql-connector-java-3.1.13-bin.jar) and in War project folder �WEB-INF/lib� and in [TomcatServer]\common\lib.
    I have in folder�WEB-INF/lib� following files:
    antlr.jar
    commons-beanutils.jar
    commons-collections.jar
    commons-digester.jar
    commons-fileupload.jar
    commons-logging.jar
    commons-validator.jar
    jakarta-oro.jar
    jsf-api.jar
    jsf-impl.jar
    jstl.jar
    mysql-connector-java-3.1.13-bin.jar
    standard.jar
    struts.jar
    I'm using:
    NetBeans 5.5 Build200610171010 (bundled Tomcat 5.5.17)
    Ent.Pack 20061020 Visual Wb Pack 061103
    OS WinXP SP2
    Java 1.5.0_10
    MySQL 5.0.18-nt
    1:<%@page contentType="text/html"%>
    2:<%@page pageEncoding="UTF-8"%>
    8: <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    9: <%@taglib uri="http://java.sun.com/jstl/sql" prefix="sql"%>
    10:
    11: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    12: "http://www.w3.org/TR/html4/loose.dtd">
    13:
    14: <sql:setDataSource var="ds"
    15: driver="com.mysql.jdbc.Driver"
    16: url="jdbc:mysql://localhost:3306/test"
    17: user="root"
    18: password="xxxx"/>
    19:
    20:
    21:<sql:query sql="select name, age from People" var="res"
    22: dataSource="${ds}"/>
    I have received report on mistake when entered code at the top:
    �/index.jsp [21;0] According to TLD or attribute directive in tag file, attribute dataSource does not accept any expressions�
    I used instead of (dataSource="${ds}")->(dataSource="ds") but this did not work.
    After build and run I have received
    =========================================START=================================
    HTTP Status 500
    type Exception report:
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: /index.jsp(21,0) According to TLD or attribute directive in tag file, attribute dataSource does not accept any expressions
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    root cause
    org.apache.jasper.JasperException: /index.jsp(21,0) According to TLD or attribute directive in tag file, attribute dataSource does not accept any expressions
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
    org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:955)
    org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:710)
    org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    org.apache.jasper.compiler.Validator.validate(Validator.java:1489)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:166)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
    Apache Tomcat/5.5.17
    =======================================END================================
    Error: "According to TLD or attribute directive in tag file, attribute dataSource does not accept any expressions" - but according to documentation such parameter possible.
    BUT WHEN JOINING With DATABASE FROM SERVLET ALL WORK FINE.
    I read this doc - [http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html], this applicable if I Tomcat Admin, but i'am not Admin
    I simply user, i.e. I want to place its database on virtual host (Tomcat+(JSP-JSTL)+MySQL).
    There is idea how can resolve this problem
    Thank you in advance ;)

    For all how have similar problem.
    Decision instead of these ways
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
    it is necessary to indicate these
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

  • Error when connecting to mysql

    hi
    i m getting error when i want to connect with mysql
    the errors is below
    MySQL JDBC Driver not found ...
    Exception in thread "main" java.lang.ClassNotFoundException: org.gjt.mm.mysql.D
    iver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:130)
    at test.testDriver(test.java:42)
    at test.test(test.java:12)
    at test.main(test.java:127)
    plz help me
    kaleem

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=%2Bforum%3A48&qt=%22java.lang.ClassNotFoundException%22&x=9&y=10

  • Connect to mysql in another machine

    Hi, there,
    I have two database. One is oracle in my local machine, another is mysql in another machine. Now, I made a jsp program to control the two database concurrently. When I connect to mysql, I got errors:
    Internal Servlet Error:
    javax.servlet.ServletException: Server configuration denies access to data source
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
    at jspForOracle._0002fjspForOracle_0002fmodiProcess_0002ejspmodiProcess_jsp_1._jspService(_0002fjspForOracle_0002fmodiProcess
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
    at org.apache.tomcat.core.Handler.service(Handler.java:286)
    at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
    at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
    at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
    at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
    at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
    at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
    at java.lang.Thread.run(Thread.java)
    My local machine is : Redhat7.1, tomcat and oracle
    Mysql machine is : Slackware, tomcat and mysql
    I can ping and ssh the mysql machine. And I grant the mysql table for the permission to access the table. But still the same thing. What the problem?
    Thank you in advance
    peter

    in your error message:
    javax.servlet.ServletException: Server configuration denies access to data source
    The server being referred to is the mysql server. Mysql has uid and password like all db's, but in addition, it has security that is sensitive to the source of the connection. Just because you have a valid uid and password doesn't mean that you will be able to connect from anywhere.
    This data is in the user table of the mysql database, which is included by default in every mysql installation. What you need to do is edit the privileges of the user account that you're using to connect to mysql from the jsp. There is some good documetation on user administration here:
    http://www.mysql.com/documentation/mysql/bychapter/

  • Connecting to MySQL from Sun One Studio

    Hi,
    I am trying to connect to the MySQL from the Sun One Studio 5. I followed these steps.
    1. I downloaded the MySQL software and installed on my local computer, it was successful.
    2. I got the drivers [b][b][b]mysql-connector-java-3.0.8-stable-bin.jar and placed it in the <stdudio5>/lib/ext/ directory.
    3. And I successfully got through that one also, and in the database section it showed me the icon for connecting to mysql database. I gave the url, username, and password. It worked fine.
    4. Then I created the connection pool, JDBC resource, and Persistence manager for my server instance. It was also successful.
    5. When I built a cmp bean accessing the table in mySQL database, it is giving me these errors.
    If you notice these error, it is asking for vendor type. But i don't have any option to choose the vendor type when i configured the database resources.
    Can soem body suggest some other method and clear this error. I am struggling with this since a week.
    Thank you.
    [[b]09/Oct/2003:11:12:31] WARNING ( 3476): Cannot get database metadata: database product name.
    java.sql.SQLException: com.sun.enterprise.repository.J2EEResourceException
    java.lang.ClassNotFoundException: org.gjt.mm.mysql.jdbc2.optional.MysqlDataSource
    at com.sun.enterprise.resource.SystemJdbcDataSource.internalGetConnection(SystemJdbcDataSource.java:252)
    at com.sun.enterprise.resource.SystemJdbcDataSource.getConnection(SystemJdbcDataSource.java:154)
    at com.sun.jdo.spi.persistence.support.sqlstore.ejb.TransactionHelperImpl.getConnection(TransactionHelperImpl.java:171)
    at com.sun.jdo.spi.persistence.support.sqlstore.ejb.EJBHelper.getConnection(EJBHelper.java:169)
    at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getDBName(SQLPersistenceManagerFactory.java:781)
    at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getFromPool(SQLPersistenceManagerFactory.java:709)
    at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getPersistenceManager(SQLPersistenceManagerFactory.java:598)
    at com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl.getPersistenceManager(PersistenceManagerFactoryImpl.java:770)
    at com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl.getPersistenceManager(PersistenceManagerFactoryImpl.java:660)
    at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl.jdoGetPersistenceManager(JobinfoBean_1956195957_ConcreteImpl.java:1479)
    at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl.ejbFindByTitle(JobinfoBean_1956195957_ConcreteImpl.java:541)
    at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl_RemoteHomeImpl.findByTitle(JobinfoBean_1956195957_ConcreteImpl_RemoteHomeImpl.java:175)
    at JAdminEntityBeans._JobinfoHome_Stub.findByTitle(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.sun.forte4j.j2ee.ejbtest.webtest.InvocableMethod$MethodIM.invoke(InvocableMethod.java:231)
    at com.sun.forte4j.j2ee.ejbtest.webtest.EjbInvoker.getInvocationResults(EjbInvoker.java:96)
    at com.sun.forte4j.j2ee.ejbtest.webtest.DispatchHelper.getForward(DispatchHelper.java:189)
    at jasper.dispatch_jsp._jspService(_dispatch_jsp.java:136)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:552)
    at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:368)
    at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:287)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:720)
    at org.apache.catalina.core.StandardWrapperValve.access$000(StandardWrapperValve.java:118)
    at org.apache.catalina.core.StandardWrapperValve$1.run(StandardWrapperValve.java:278)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:274)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
    at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
    at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
    [09/Oct/2003:11:12:31] INFO ( 3476): Bean Jobinfo method ejbFindByTitle: problems running JDOQL query.
    com.sun.jdo.api.persistence.support.JDOFatalInternalException: Failed to get the vendor type for the data store.
    NestedException: java.sql.SQLException: com.sun.enterprise.repository.J2EEResourceException
    java.lang.ClassNotFoundException: org.gjt.mm.mysql.jdbc2.optional.MysqlDataSource
    at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getDBName(SQLPersistenceManagerFactory.java:802)
    at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getFromPool(SQLPersistenceManagerFactory.java:709)
    at com.sun.jdo.spi.persistence.support.sqlstore.impl.SQLPersistenceManagerFactory.getPersistenceManager(SQLPersistenceManagerFactory.java:598)
    at com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl.getPersistenceManager(PersistenceManagerFactoryImpl.java:770)
    at com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl.getPersistenceManager(PersistenceManagerFactoryImpl.java:660)
    at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl.jdoGetPersistenceManager(JobinfoBean_1956195957_ConcreteImpl.java:1479)
    at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl.ejbFindByTitle(JobinfoBean_1956195957_ConcreteImpl.java:541)
    at JAdminEntityBeans.JobinfoBean_1956195957_ConcreteImpl_RemoteHomeImpl.findByTitle(JobinfoBean_1956195957_ConcreteImpl_RemoteHomeImpl.java:175)
    at JAdminEntityBeans._JobinfoHome_Stub.findByTitle(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.sun.forte4j.j2ee.ejbtest.webtest.InvocableMethod$MethodIM.invoke(InvocableMethod.java:231)
    at com.sun.forte4j.j2ee.ejbtest.webtest.EjbInvoker.getInvocationResults(EjbInvoker.java:96)
    at com.sun.forte4j.j2ee.ejbtest.webtest.DispatchHelper.getForward(DispatchHelper.java:189)
    at jasper.dispatch_jsp._jspService(_dispatch_jsp.java:136)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:552)
    at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:368)
    at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:287)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:720)
    at org.apache.catalina.core.StandardWrapperValve.access$000(StandardWrapperValve.java:118)
    at org.apache.catalina.core.StandardWrapperValve$1.run(StandardWrapperValve.java:278)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:274)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
    at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
    at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)

    The AS7 error suggests that you have not set up the server startup classpath to include the driver jar. The steps to do this are included in the article mentioned in Chris's reply, namely:
    http://developers.sun.com/tools/javatools/tips/tip03-08-22.html
    Note especially the part starting with Step 3 under the section "Enabling the JDBC Driver in the IDE."
    -Jane

  • Problem to connect to mysql from servlet using a javabean

    Hi,
    I'm new here and beginner on java to.
    I have problem to connect to MySql database, by a connection javabean.
    It's the following: a HTML page calls a servlet and this servlet imports the package connection javabean.
    It has no problem when I establish the connection inside the servlet, with all its methods (public and private). But i want to separate the code connection from servlet.
    Detail: there is no problem, using the javabean to connect to MS Access database.
    I put "mysql-connector-java-3.1.12-bin.jar" file inside WEB-INF/lib application and common/lib directories.
    I set the classpath:
    SET CLASSPATH=%CATALINA_HOME%\COMMON\LIB\mysql-connector-java-3.1.12-bin.jar;%CLASSPATH%
    I think that the servlet cannot create an instance of javabean, because passed by catch exception of the servlet init method.
    But I don't know why.
    Please Why?
    Below there are the fragment of errors, servlet code e javabean code.
    Thank you.
    Zovao.
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    java.lang.NullPointerException
    at CadServletFileBeanConexArq.doPost(CadServletFileBeanConexArq.java:47)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
    Note: The line 47 is calling insertIntoDB javabean method.
    ========///////////////===============
    // Here is the servlet CadServletFileBeanConexArq.java
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.sql.*;
    import conJdbc.*;
    public class CadServletFileBeanConexArq extends HttpServlet {
    public ConexPed connect = null;
    private String driver = "com.mysql.jdbc.Driver";
    private String URL = "jdbc:mysql://localhost:3306/cadastro";
    public void init( ServletConfig config )
    throws ServletException
    super.init( config );
    try
    connect = new ConexPed(driver, URL, "monty", "some_pass");
    catch ( Exception e )
    e.printStackTrace();
    connect = null;
    public void doPost( HttpServletRequest req,
    HttpServletResponse res )
    throws ServletException
    boolean success = true;
    String email, nome, sobrenome, produto, valor;
    email = req.getParameter( "Email" );
    nome = req.getParameter( "Nome" );
    sobrenome = req.getParameter( "Sobrenome" );
    produto = req.getParameter( "Produto" );
    valor = req.getParameter( "Valor" );
    res.setContentType( "text/html" );
    if ( email.length() > 0 && nome.length() > 0 && sobrenome.length() > 0 && valor.length() > 0 )
    /* inserting data */
    success = connect.insertIntoDB(
    "'" + email + "','" + nome + "','" + sobrenome + "','" + produto + "'", Double.parseDouble(valor) );
    //closing connection
    public void destroy()
    connect.fecharConexao();
    =============///////////////============
    Here is the JavaBean.
    package conJdbc;
    import java.sql.*;
    public class ConexPed
    public Connection connection;
    public Statement statement;
    public ConexPed (String driver, String urlServidor, String user, String password)
    try
    Class.forName(driver);
    connection = DriverManager.getConnection(urlServidor,user,password);
    catch (ClassNotFoundException ex)
    System.out.println("N�o foi poss�vel encontrar a classe do Driver: " + driver);
    catch (SQLException ex)
    System.out.println("N�o foi poss�vel conectar ao servidor");
    try
    statement = connection.createStatement();
    catch (SQLException ex)
    System.out.println("N�o foi poss�vel criar a statement");
    *Inserting data to database
    public synchronized boolean insertIntoDB( String stringtoinsert, double valor)
    try
    statement.executeUpdate( "INSERT INTO pedido values (" + stringtoinsert + " , " + valor + ");" );
    catch ( Exception e ) {
    System.err.println(
    "ERROR: Problemas ao adicionar nova entrada" );
    e.printStackTrace();
    return false;
    return true;
    * Close statement.
    public void fecharStatement()
    try
    statement.close();
    catch (SQLException ex)
    ex.printStackTrace();
    * close database
    public void fecharConexao()
    try
    connection.close();
    catch (SQLException ex)
    ex.printStackTrace();
    }

    Hi,
    I'm new here and beginner on java to.
    I have problem to connect to MySql database, by a connection javabean.
    It's the following: a HTML page calls a servlet and this servlet imports the package connection javabean.
    It has no problem when I establish the connection inside the servlet, with all its methods (public and private). But i want to separate the code connection from servlet.
    Detail: there is no problem, using the javabean to connect to MS Access database.
    I put "mysql-connector-java-3.1.12-bin.jar" file inside WEB-INF/lib application and common/lib directories.
    I set the classpath:
    SET CLASSPATH=%CATALINA_HOME%\COMMON\LIB\mysql-connector-java-3.1.12-bin.jar;%CLASSPATH%
    I think that the servlet cannot create an instance of javabean, because passed by catch exception of the servlet init method.
    But I don't know why.
    Please Why?
    Below there are the fragment of errors, servlet code e javabean code.
    Thank you.
    Zovao.
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    java.lang.NullPointerException
    at CadServletFileBeanConexArq.doPost(CadServletFileBeanConexArq.java:47)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
    Note: The line 47 is calling insertIntoDB javabean method.
    ========///////////////===============
    // Here is the servlet CadServletFileBeanConexArq.java
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.sql.*;
    import conJdbc.*;
    public class CadServletFileBeanConexArq extends HttpServlet {
    public ConexPed connect = null;
    private String driver = "com.mysql.jdbc.Driver";
    private String URL = "jdbc:mysql://localhost:3306/cadastro";
    public void init( ServletConfig config )
    throws ServletException
    super.init( config );
    try
    connect = new ConexPed(driver, URL, "monty", "some_pass");
    catch ( Exception e )
    e.printStackTrace();
    connect = null;
    public void doPost( HttpServletRequest req,
    HttpServletResponse res )
    throws ServletException
    boolean success = true;
    String email, nome, sobrenome, produto, valor;
    email = req.getParameter( "Email" );
    nome = req.getParameter( "Nome" );
    sobrenome = req.getParameter( "Sobrenome" );
    produto = req.getParameter( "Produto" );
    valor = req.getParameter( "Valor" );
    res.setContentType( "text/html" );
    if ( email.length() > 0 && nome.length() > 0 && sobrenome.length() > 0 && valor.length() > 0 )
    /* inserting data */
    success = connect.insertIntoDB(
    "'" + email + "','" + nome + "','" + sobrenome + "','" + produto + "'", Double.parseDouble(valor) );
    //closing connection
    public void destroy()
    connect.fecharConexao();
    =============///////////////============
    Here is the JavaBean.
    package conJdbc;
    import java.sql.*;
    public class ConexPed
    public Connection connection;
    public Statement statement;
    public ConexPed (String driver, String urlServidor, String user, String password)
    try
    Class.forName(driver);
    connection = DriverManager.getConnection(urlServidor,user,password);
    catch (ClassNotFoundException ex)
    System.out.println("N�o foi poss�vel encontrar a classe do Driver: " + driver);
    catch (SQLException ex)
    System.out.println("N�o foi poss�vel conectar ao servidor");
    try
    statement = connection.createStatement();
    catch (SQLException ex)
    System.out.println("N�o foi poss�vel criar a statement");
    *Inserting data to database
    public synchronized boolean insertIntoDB( String stringtoinsert, double valor)
    try
    statement.executeUpdate( "INSERT INTO pedido values (" + stringtoinsert + " , " + valor + ");" );
    catch ( Exception e ) {
    System.err.println(
    "ERROR: Problemas ao adicionar nova entrada" );
    e.printStackTrace();
    return false;
    return true;
    * Close statement.
    public void fecharStatement()
    try
    statement.close();
    catch (SQLException ex)
    ex.printStackTrace();
    * close database
    public void fecharConexao()
    try
    connection.close();
    catch (SQLException ex)
    ex.printStackTrace();
    }

  • Connecting to MySql Database

    java.lang.NoClassDefFoundError: java/sql/Savepoint
         at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:268)
         at java.sql.DriverManager.getConnection(DriverManager.java:517)
         at java.sql.DriverManager.getConnection(DriverManager.java:199)
         at mysql.Untitled1.main(Untitled1.java:28)
    Exception in thread "main" What happened now I tried to connect to a MySql database and it gives me this error I have the new Connector J for this purpose but still

    Now I Installed the J2SDK 1.4.1 and compiled the following class with the command line javac
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    public class myClass {
      public myClass() {
      public static void main(String[] args) {
       myClass here = new myClass();
      try{
       Class.forName("com.mysql.jdbc.Driver");
      catch (Exception e){
      e.printStackTrace();
      try{
       Connection con = DriverManager.getConnection("jdbc:mysql://localhost/test?user=amrhsn&password=ammars");
       catch (Exception e){
        e.printStackTrace();
    }Although it compiled perfectly but on running gives the following error
    Exceptoin in thread "main" java.lang.NoClassDefFoundError : myClass
    and the same file when I try to compile it with my JBuilder 4 Enterprise edition after changing the JDK from 1.3.3. to J2SDK 1.4.1 give the following error.
    "myClass.java": Error #: 750 : initialization error: com.borland.compiler.symtab.LoadError: class file has wrong version 48.0
    What is the problem!!!!!

  • Problem connecting to MySQL thro Applet using JDBC

    Hi,
    I'm trying to use an applet to connect to MySQL thro JDBC. The applet, the IE client that loads the HTML, and MySQL all reside on the same machine. But I'm getting the following error:"ClassNotFoundException: com.mysql.jdbc.Driver". But I'm able to connect using a Java application and run and display SQL query results. Any ideas are highly appreciated. Here're are the two pieces of code:
    /****** Java Application *****/
    import java.sql.*;
    public class MySQL_App {
    public static void main(String args[]) {
              String url = "jdbc:mysql://localhost/test";
         try {
                   Class.forName("com.mysql.jdbc.Driver");
         catch(java.lang.ClassNotFoundException e) {
                   System.err.print("ClassNotFoundException: ");
                   System.err.println(e.getMessage());
    /****** Java Applet *****/
    import java.awt.*;
    import javax.swing.*;
    import netscape.javascript.*;
    import java.sql.*;
    public class MySQL_Applet extends JApplet {
         JSObject win;
         public void init() {
              win = JSObject.getWindow(this);
         public void callShowMessage() {
              String url = "jdbc:mysql://" + this.getDocumentBase().getHost() + "/test";
              String[] args = new String[1];
         args[0] = "" ;
         try {
              Class.forName("com.mysql.jdbc.Driver");
         catch(java.lang.ClassNotFoundException e) {
                   args[0] += "ClassNotFoundException " + e.getMessage() ;
         win.call("showMessage", args);
    }

    mmm i, think that may here we've 2 possibles answers:
    1) Did u read about "Applet Security"? my point is that you haven't acces to your local var "path" or "classpath".
    2) Maybe u didn't especificate the MySQl path in ur classpath;
    Check this 2 points

  • Remote connection to MySQL

    I am trying in Java to connect remotely to a database and use the following code:
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    import java.sql.*;
    public class Test {
    public static void main(String args[]) {
    Connection con = null;
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    con = DriverManager.getConnection("jdbc:mysql://llsti.org:3306/universalaccess?user=*****&password=****");
    if(!con.isClosed())
    System.out.println("Successfully connected to " +
    "MySQL server using TCP/IP...");
    } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
    } finally {
    try {
    if(con != null)
    con.close();
    } catch(SQLException e) {}
    But it doesnt do anything.. it compiles properly but then it just stuck in getConnection(). it doesnt print thereafter.
    Any suggestion would be of great help.
    Thanks,
    Akhil

    Hi,
    So what network settings I am suppose to perform? I
    would be really greatful for any more suggestions.
    I cannot put this really any clearer because it's been told to you before. You are getting a 2003 error. This is what the MySQL site has to say about that error.
    The error (2003) Can't connect to MySQL server on 'server' (10061) indicates that the network connection has been refused. You should check that there is a MySQL server running, that it has network connections enabled, the network port you specified is the one configured on the server, and that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.
    Please talk to your local network administrator and/or the administrator of the MySQL database for assistance. Either the database is not listening on that port or there is a firewall blocking your access either at your end or at the server end.
    This is NOT a Java problem. You cannot connect using any other tool to this database.

Maybe you are looking for

  • Netbeans and Firebird DB

    I'm trying to get Netbeans to connect to a Firebird database so I can try out the basic database application template. I am able to make a connection and it logs in to the database. It then takes me to the Advanced tab and asks about which database s

  • When exporting versions (from DNG-to JPEG org size) they get very smal?

    when exporting versions in aperture (from DNG-to JPEG org size) they get very smal? Why cant they stay the same size and kvalety as the DNG?

  • Posting GR

    Hello   when i am trying to post the GR it's showing the error msg as "period 005/2011 is not open for account type M and G/L 304000 pls guide me Edited by: Csaba Szommer on May 22, 2011 3:12 PM

  • Three computers left for downloads of my music.

    I recently had a virus that attacked my executable files of my computer. Therefore I had to totally reconfigure my computer. When reloading my itune file to my same computer, it said that I have a new computer and used one of my computers for my shar

  • Error extracting data from essbase cube using MDX method

    Hi, We have some problems extracting data from essbase cube using MDX method, we believe that the problem is the MDX query, this is the problem and query: ERROR: [DwgCmdExecutionThread]: Cannot perform cube view operation. Analytic Server Error(12600