facebook

BasicDataSource

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #294985 Reply

    Mary
    Member

    Goal: Access MySql 5 through the embedded Tomcat 6 in MyEclipse 6.5.

    I’m trying to access a MySql 5 database and having problems creating the connection. I want to use a username and password to login; however, Ithe BassicDataSource does not have a constructorwith any parameters. I don’t know where the BasicDataSource is being chosen over another one; I am not writing that code.

    I have read several tutorials; I think it’s the fact that I don’t grasp what is going on under the covers such as where the BasicDataSource is being specified.

    #294990 Reply

    Mary
    Member

    Here is my entry in the context.xml file:
    <?xml version=”1.0″ encoding=”UTF-8″?>
    <Context>
    <!– Specify a JDBC datasource –>
    <Resource name=”jdbc/TestDB”
    auth=”Container”
    type=”javax.sql.DataSource”
    username=”tuser”
    password=”tpwd”
    driverClassName=”com.mysql.jdbc.Driver”
    url=”jdbc:mysql://localhost:3306/TestDB?autoReconnect=true”
    validationQuery=”select count(*) from registered_users”
    maxActive=”10″
    maxIdle=”4″/>
    </Context>

    #295022 Reply

    support-joy
    Member

    kentucky_b,

    Your current post is more to do with software development. I am moving this thread to the relevant post.

    If you are learning a new technology, and you need help/clarification, I suggest you to use the “Software Development” forum -> https://www.genuitec.com/forums/topics/myeclipse/off-topic/. This will ensure that your problem is addressed by the right group. 🙂

    #295078 Reply

    Mary
    Member

    Here is the stack trace from the exception thrown when trying to obtain a db connection:

    UtilitiesServlet.getDBConnection catch block:

    org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Server connection failure during transaction. Due to underlying exception: ‘java.net.ConnectException: Connection timed out: connect’.

    ** BEGIN NESTED EXCEPTION **

    java.net.ConnectException
    MESSAGE: Connection timed out: connect

    STACKTRACE:

    java.net.ConnectException: Connection timed out: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2921)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
    at GradProject.Utilities.getDBConnection(Utilities.java:53)
    at GradProject.Utilities.findUserInDatabase(Utilities.java:139)
    at GradProject.ProcessLoginServlet.doPost(ProcessLoginServlet.java:29)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)

    ** END NESTED EXCEPTION **

    Attempted reconnect 3 times. Giving up.)

    ProcessLoginServlet.doPost: User not found in the database!!!

    #295079 Reply

    Mary
    Member

    I notice Tomcat is trying to create a BasicDataSource connection even though I am specifying a DataSource connection. I am not sure this post is in the best forum as it does seem tohahve to do with the Tomcat 6 server embedded in MyEclipse 6.5 which does not have the same capabilities or requirements of an external server. My context.xml is included in this post on an earlier date. I appreciate any advice as to how to proceed. I really need to get this connection created to continue. Thank you very much.

    #295080 Reply

    Mary
    Member

    Here is my Java code to obtain a database connection:

    public static Connection getDBConnection()
    {
    method = “getDBConnection”;
    System.out.print(“\n\n” + className + “.” + method);
    try
    {
    Context initCtx = new InitialContext();
    System.out.print(“\n\n initCtx = ” + initCtx.toString());
    Context envCtx = (Context) initCtx.lookup(“java:comp/env”);
    System.out.print(“\n\n envCtx = ” + envCtx.toString());
    DataSource ds =
    (DataSource)envCtx.lookup(“jdbc/TestDB”);

    System.out.print(“\n\n ds = ” + ds.toString());
    conn = ds.getConnection();
    System.out.print(“\n\n conn = ” + conn.toString());
    return conn;
    }
    catch (Exception e)
    {

    System.out.print(“\n\n” + className + “.” + method + ” catch block: \n\n” + e.toString());
    conn = null;
    }
    return conn;
    }

    #295262 Reply

    Loyal Water
    Member

    Moving to Off Topic >> Software Development.

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: BasicDataSource

You must be logged in to post in the forum log in