Package javax.sql

Examples of javax.sql.DataSource


    @AroundInvoke
    public Object intercept(final InvocationContext ic) throws Exception{
        if (ic.getMethod().toString().contains("accessJNDI")) {

            //JNDI Access
            DataSource dsViaJNDI = (DataSource) JNDIHelper.getJavaCompEnvResource("jdbc/jdbc_1");
            TableManager cTest = new TableManager(dsViaJNDI);
            cTest.test("tmpTable" + cTest.hashCode());

        } else if (ic.getMethod().toString().contains("accessEJB")) {
View Full Code Here


     * @param db1 the database name in the registry.
     * @throws Exception if an error occurs.
     */
    private void makeSQLError(final String db1) throws Exception {
        Connection connection = null;
        DataSource ds = DBHelper.getDataSource(db1);
        try {
            // gets a connection
            connection = ds.getConnection();
            PreparedStatement stmUpdate = null;
            // connect and insert a query with error
            try {
                stmUpdate = connection.prepareStatement("CREATE TABLE error(");
                stmUpdate.executeUpdate();
View Full Code Here

   protected boolean checkNoBindingData() throws Exception
   {
      InitialContext ctx = new InitialContext();

      TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
      DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");
     
      javax.transaction.Transaction txOld = mgr.suspend();
      mgr.begin();
     
      java.sql.Connection conn = null;
     
      PreparedStatement ps = null;
     
      ResultSet rs = null;

      try
      {
         conn = ds.getConnection();
         String sql = "SELECT * FROM JBM_POSTOFFICE";
         ps = conn.prepareStatement(sql);
        
         rs = ps.executeQuery();
        
View Full Code Here

      }
     
      InitialContext ctx = new InitialContext();

      TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
      DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");
     
      javax.transaction.Transaction txOld = mgr.suspend();
      mgr.begin();
     
      java.sql.Connection conn = null;
     
      PreparedStatement ps = null;
     
      ResultSet rs = null;

      try
      {
         conn = ds.getConnection();
         String sql = "SELECT * FROM JBM_MSG_REF";
         ps = conn.prepareStatement(sql);
        
         rs = ps.executeQuery();
        
View Full Code Here

import cn.org.rapid_framework.generator.provider.db.sql.SqlFactory;

public class SQLErrorCodeSQLExceptionTranslatorTest extends GeneratorTestCase {
   
    public void testTranslator() {
        DataSource ds = DataSourceProvider.getDataSource();
       
        SQLErrorCodeSQLExceptionTranslator translator = SQLErrorCodeSQLExceptionTranslator.getSQLErrorCodeSQLExceptionTranslator(ds);
        try {
            execute("insert into role_permission(permissoin_id,role_id) values (123,123)");
            fail();
View Full Code Here

        new SqlFactory().parseSql("insert into role_permission(permissoin_id,role_id) values (123,123)");
        new SqlFactory().parseSql("insert into user_info(user_id,username,password) values (123,'123',123)");
    }
   
    public void execute(String sql) throws SQLException {
        DataSource ds = DataSourceProvider.getDataSource();
        Connection conn = ds.getConnection();
        PreparedStatement ps = conn.prepareStatement(sql);
        if(ps.execute()) {
        }
        ps.close();
        conn.close();
View Full Code Here

     * Test access to the java:comp/env.
     * @throws Exception if a problem occurs.
     */
    public void access00() throws Exception {
        // JNDI Access
        DataSource ds = (DataSource) JNDIHelper.getJavaCompEnvResource("jdbc/jdbc_1");
        TableManager cTest = new TableManager(ds);
        cTest.test("tmpTable" + ds.hashCode());
    }
View Full Code Here

        sb.append(a);

        // Assert there was resource injection and ENC is correct
        Object o = sessionContext.lookup("jdbc/myJDBC");

        DataSource ds = null;
        // cast
        if (o != null) {
            ds = (DataSource) o;
        } else {
            throw new IllegalStateException("No resource found in ENC env");
        }

        try {
            Connection c1 = datasource.getConnection();
            c1.close();
            Connection c2 = ds.getConnection();
            c2.close();
        } catch (SQLException e) {
            throw new IllegalStateException("Cannot use the JDBC connection");
        }
View Full Code Here

         // was deployment succesful?
         assertTrue("deployed successful : " + isDeployed, isDeployed);

         // see if we can get a connection
         InitialContext ic = new InitialContext();
         DataSource ds = (DataSource) ic.lookup(jndiName);
         Connection connection = ds.getConnection();
         connection.close();

         // undeploy module
         undeployModule(module);
         // remove module
         removeModule(module);

         // regenerate with wrong usename
         props.put("user-name", "rogue-admin");
         module = createModule(module, template, props);

         // deploy again
         isDeployed = deployModule(module);

         // was deployment succesful?
         assertTrue("deployed successful : " + isDeployed, isDeployed);

         // lookup the datasource again and see if we can get a connection
         // it should fail this time
         try
         {
            ds = (DataSource) ic.lookup(jndiName);
            connection = ds.getConnection();
            fail("Shouldn't reach this point");
         }
         catch (Exception e)
         {
            // ok
View Full Code Here

         // But we should NOT be able to get a connection
         try
         {
            InitialContext ic = new InitialContext();
            DataSource ds = (DataSource) ic.lookup(jndiName);
            fail("Shouldn't reach this point");
         }
         catch (Exception e)
         {
            // Ok, undeploy the module
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.