Package javax.sql

Examples of javax.sql.DataSource


      this.datasource = datasource;
   }

   protected void initDatabase() throws Exception
   {
      DataSource ds = (DataSource)new InitialContext().lookup(datasource);
      Connection conn = ds.getConnection();
      boolean load = false;

      Statement st = conn.createStatement();
      ResultSet rs = null;
      try
View Full Code Here


   public void testDataSource() throws Exception
   {
      PortalContainer container = PortalContainer.getInstance();
      container.getComponentInstanceOfType(InitialContextInitializer.class);
      DataSource ds = (DataSource)new InitialContext().lookup("jdbcexo");
      assertNotNull(ds);
      Connection conn = ds.getConnection();
      DatabaseMetaData databaseMD = conn.getMetaData();
      String db = databaseMD.getDatabaseProductName() + " " + databaseMD.getDatabaseProductVersion() + "." +
         databaseMD.getDatabaseMajorVersion() + "." +  databaseMD.getDatabaseMinorVersion();
      String driver = databaseMD.getDriverName() + " " + databaseMD.getDriverVersion() + "." +
         databaseMD.getDriverMajorVersion() + "." +  databaseMD.getDriverMinorVersion();
View Full Code Here

  private XAConnection createConnection() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
   
    TestLogger.log("Creating Datasource Connection: \"" + this.serverName + " - " + this.databaseName + "\""); //$NON-NLS-1$ //$NON-NLS-2$

    DataSource ds = (DataSource) Class.forName(this.driver).newInstance();

    if (ds instanceof BaseDataSource) {

      BaseDataSource dataSource = (BaseDataSource) ds;
View Full Code Here

    public Connection getConnection() throws QueryTestFailedException {
  validate();
  try {
      InitialContext ctx = new InitialContext();
      DataSource source = (DataSource) ctx.lookup(jndi_name);

      if (source == null) {
    String msg = "Unable to find jndi source " + jndi_name;//$NON-NLS-1$

    QueryTestFailedException mme = new QueryTestFailedException(msg);//$NON-NLS-1$
    throw mme;
      }
      Connection conn = source.getConnection();
      return conn;
  } catch (QueryTestFailedException qtfe) {
      throw qtfe;
  } catch (Exception e) {
      throw new QueryTestFailedException(e);
View Full Code Here

                //## Java 1.4 begin ##
            } else if (javax.naming.Context.class.isAssignableFrom(d)) {
                // JNDI context
                try {
                    Context context = (Context) d.newInstance();
                    DataSource ds = (DataSource) context.lookup(url);
                    String user = prop.getProperty("user");
                    String password = prop.getProperty("password");
                    if (StringUtils.isNullOrEmpty(user) && StringUtils.isNullOrEmpty(password)) {
                        return ds.getConnection();
                    }
                    return ds.getConnection(user, password);
                } catch (Exception e) {
                    throw Message.convert(e);
                }
                //## Java 1.4 end ##
            } else {
View Full Code Here

            sessData.setRowsPerPage(rowsPerPage);
            sessData.setHistorySize(historySize);
            sessData.addQueryToHistory(sql);
        }

        DataSource dataSource = null;

        try {
            dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName);
        } catch (NamingException e) {
            request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[]{resourceName}));
        }

        if (dataSource == null) {
            request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[]{resourceName}));
        } else {
            List results = null;
            int rowsAffected = 0;

            try {
                // TODO: use Spring's jdbc template?
                Connection conn = dataSource.getConnection();

                try {
                    conn.setAutoCommit(true);
                    PreparedStatement stmt = conn.prepareStatement(sql);
View Full Code Here

*/
public class ConnectionTestController extends ContextHandlerController {

    protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception {
        String resourceName = ServletRequestUtils.getStringParameter(request, "resource");
        DataSource dataSource = null;

        try {
            dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName);
        } catch (NamingException e) {
            request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[]{resourceName}));
        }

        if (dataSource == null) {
            request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[]{resourceName}));
        } else {
            try {
                // TODO: use Spring's jdbc template?
                Connection conn = dataSource.getConnection();
                try {
                    DatabaseMetaData md = conn.getMetaData();

                    List dbMetaData = new ArrayList();

View Full Code Here

        for (int i = 0; i < 100; i++) {
            Connection conn = pool.getConnection();
            conn.close();
        }
        pool.dispose();
        DataSource ds = pool;
        assertThrows(IllegalStateException.class, ds).
                getConnection();
        assertThrows(UnsupportedOperationException.class, ds).
                getConnection(null, null);
    }
View Full Code Here

      throw new SQLException("JNDI DataSource is invalid; no connection path is defined.");
    }
    try
    {
      final Context ctx = getInitialContext();
      final DataSource ds = findDataSource(ctx, connectionPath);

      final String realUser;
      final String realPassword;
      if (username != null)
      {
        realUser = username;
      }
      else
      {
        realUser = user;
      }
      if (this.password != null)
      {
        realPassword = this.password;
      }
      else
      {
        realPassword = password;
      }

      if (realUser == null)
      {
        final Connection connection = ds.getConnection();
        if (connection == null)
        {
          throw new SQLException("JNDI DataSource is invalid; it returned null without throwing a meaningful error.");
        }
        return connection;
      }

      final Connection connection = ds.getConnection(realUser, realPassword);
      if (connection == null)
      {
        throw new SQLException("JNDI DataSource is invalid; it returned null without throwing a meaningful error.");
      }
      return connection;
View Full Code Here

     */
    public Connection getConnection(  )
        throws NamingException,
                   SQLException
    {
        DataSource ds = ( DataSource ) new InitialContext(  ).lookup( _datasource );
        return ds.getConnection(  );
    }
View Full Code Here

TOP

Related Classes of javax.sql.DataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.