Re: IBatis returns null

Vic Cekvenich <[email protected]> Fri, 17 Oct 2003 10:19:29 -0400
Newsgroups gmane.comp.java.mvc.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------090802090703050807010609
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Just for test... try JDBC w/o DAO.
.V

Peyathevar, Santhi {PBG} wrote:

>Vic,
>
>i tried connecting to PostGres DB. It is fine.
>It is only with the Oracle that i am getting nulls.
>May be i should change the Oracle Driver and try tonight.
>
>Every reply encourages to try one step further...
>
>Thank you very much
>Santhi
>
>
>-----Original Message-----
>From: Vic Cekvenich [mailto:[email protected]]
>Sent: Thursday, October 16, 2003 4:57 PM
>To: [email protected]
>Subject: Re: [MVC-Programmers] IBatis returns null
>
>
>I use ibatis from java console applications a lot (for batch, etc.).
>Here is my snipet that works:
>    static {  try {
>            Reader reader = 
>Resources.getResourceAsReader("properties/sql-map-config.xml");
>             _sqlMap = XmlSqlMapBuilder.buildSqlMap(reader);
>            _sqlMap.setCurrentDataSourceName("ids");
>            log.debug("we have a connection pool!");
>       }
>I am not sure where you might be stuck, can you put a few debugs in?
>.V
>
>Peyathevar, Santhi {PBG} wrote:
>
>  
>
>>Vic,
>>
>>1.i do not need a web app. Only, simple java app.
>>2.I tried both Dbcp and SimpleDataSourceFactory.
>>both give null. Connecting to oracle database.
>>I know it is connecting to the database, 
>>because it complains if i leave syntax errors.
>>
>>************************************
>>This is the sample that i am trying to run - from IBatis Web site:
>>************************************
>>SqlMapConfigExample.xml
>>
>> <datasource name="basic" default = "true"
>>
>>factory-class="com.ibatis.db.sqlmap.datasource.SimpleDataSourceFactory">
>>   <property name="JDBC.Driver" value="${driver}"/>
>>   <property name="JDBC.ConnectionURL" value="${url}"/>
>>   <property name="JDBC.Username" value="${username}"/>
>>   <property name="JDBC.Password" value="${password}"/>
>> </datasource>
>>
>> <sql-map resource="examples/sqlmap/maps/Account.xml" />
>>
>>************************************
>>
>>Account.xml
>>
>> <result-map name="indexed-account-result2"
>>class="examples.domain.Account">
>>   <property name="id"           column="ACC_ID"         columnIndex="1"/>
>>   <property name="firstName"    column="ACC_FIRST_NAME" columnIndex="2"/>
>>   <property name="lastName"     column="ACC_LAST_NAME"  columnIndex="3"/>
>>  </result-map>
>>
>><mapped-statement name="getAccount" cache-model="account-cache"
>>result-map="indexed-account-result2">
>>   select
>>     ACC_ID,
>>     ACC_FIRST_NAME,
>>     ACC_LAST_NAME
>>   from ACCOUNT
>>   where ACC_ID = #value#
>> </mapped-statement>
>>
>>*************************************
>>SqlMapConfigExample.java (Don't i have to use the datasource name "basic"
>>anywhere ?
>>
>>static
>>{
>>
>>   Reader reader =
>>Resources.getResourceAsReader("examples/sqlmap/maps/SqlMapConfigExample.xml
>>    
>>
>"
>  
>
>>);
>>   sqlMap = XmlSqlMapBuilder.buildSqlMap(reader);
>>}
>>
>>***********************************
>>QueryForListExample.java
>>
>>  SqlMap sqlMap = SqlMapConfigExample.getSqlMap();
>>
>>   try 
>>   {
>>      sqlMap.startTransaction();
>>      Account account = (Account)
>>sqlMap.executeQueryForObject("getAccount", new Integer(1));
>>      sqlMap.commitTransaction();
>>   }
>>************************************
>>Sorry about the long email
>>Santhi
>>************************************
>>
>>-----Original Message-----
>>From: Vic Cekvenich [mailto:[email protected]]
>>Sent: Thursday, October 16, 2003 3:49 PM
>>To: [email protected]
>>Subject: Re: [MVC-Programmers] IBatis returns null
>>
>>
>>It's best to use JNDI container DataSource pools, howerver:
>><datasource name="ids"
>>   
>>factory-class="com.ibatis.db.sqlmap.datasource.SimpleDataSourceFactory" 
>>default="true">
>><property name="JDBC.Driver" value="org.postgresql.Driver"/>
>><property name="JDBC.ConnectionURL" 
>>value="jdbc:postgresql://localhost:5432/bp?autoReconnect=true"/>
>><property name="JDBC.Username" value="bpuser"/>
>><property name="JDBC.Password" value="changeme"/>
>></datasource>
>>
>>aboove is a sample iBatis pool.
>>I think that was your question. From there, it is just standard iBatis.
>>
>>.V
>>
>>Peyathevar, Santhi {PBG} wrote:
>>
>> 
>>
>>    
>>
>>>All:
>>>
>>>1.I am trying to use IBatis for running some SQL
>>>
>>>   
>>>
>>>      
>>>
>>>from simple java code.
>> 
>>
>>    
>>
>>>2.using DbcpDataSourceFactory
>>>
>>>3.It connects to the database but the result is null
>>>
>>>Can anybody help?
>>>
>>>Santhi
>>>
>>>_______________________________________________
>>>MVC-Programmers mailing list
>>>[email protected]
>>>http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers
>>>
>>>
>>>
>>>
>>>   
>>>
>>>      
>>>
>>_______________________________________________
>>MVC-Programmers mailing list
>>[email protected]
>>http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers
>>_______________________________________________
>>MVC-Programmers mailing list
>>[email protected]
>>http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers
>>
>>
>> 
>>
>>    
>>
>
>_______________________________________________
>MVC-Programmers mailing list
>[email protected]
>http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers
>_______________________________________________
>MVC-Programmers mailing list
>[email protected]
>http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers
>
>
>  
>

--------------090802090703050807010609
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Just for test... try JDBC w/o DAO.<br>
.V<br>
<br>
Peyathevar, Santhi {PBG} wrote:<br>
<blockquote type="cite"
 cite="midB511B3347FBFB04492EF653DD96705AC8EC78D@pbswmu00026.corp.pep.pvt">
  <pre wrap="">Vic,

i tried connecting to PostGres DB. It is fine.
It is only with the Oracle that i am getting nulls.
May be i should change the Oracle Driver and try tonight.

Every reply encourages to try one step further...

Thank you very much
Santhi


-----Original Message-----
From: Vic Cekvenich [<a class="moz-txt-link-freetext" href="mailto:[email protected]">mailto:[email protected]</a>]
Sent: Thursday, October 16, 2003 4:57 PM
To: <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
Subject: Re: [MVC-Programmers] IBatis returns null


I use ibatis from java console applications a lot (for batch, etc.).
Here is my snipet that works:
    static {  try {
            Reader reader = 
Resources.getResourceAsReader("properties/sql-map-config.xml");
             _sqlMap = XmlSqlMapBuilder.buildSqlMap(reader);
            _sqlMap.setCurrentDataSourceName("ids");
            log.debug("we have a connection pool!");
       }
I am not sure where you might be stuck, can you put a few debugs in?
.V

Peyathevar, Santhi {PBG} wrote:

  </pre>
  <blockquote type="cite">
    <pre wrap="">Vic,

1.i do not need a web app. Only, simple java app.
2.I tried both Dbcp and SimpleDataSourceFactory.
both give null. Connecting to oracle database.
I know it is connecting to the database, 
because it complains if i leave syntax errors.

************************************
This is the sample that i am trying to run - from IBatis Web site:
************************************
SqlMapConfigExample.xml

 &lt;datasource name="basic" default = "true"

factory-class="com.ibatis.db.sqlmap.datasource.SimpleDataSourceFactory"&gt;
   &lt;property name="JDBC.Driver" value="${driver}"/&gt;
   &lt;property name="JDBC.ConnectionURL" value="${url}"/&gt;
   &lt;property name="JDBC.Username" value="${username}"/&gt;
   &lt;property name="JDBC.Password" value="${password}"/&gt;
 &lt;/datasource&gt;

 &lt;sql-map resource="examples/sqlmap/maps/Account.xml" /&gt;

************************************

Account.xml

 &lt;result-map name="indexed-account-result2"
class="examples.domain.Account"&gt;
   &lt;property name="id"           column="ACC_ID"         columnIndex="1"/&gt;
   &lt;property name="firstName"    column="ACC_FIRST_NAME" columnIndex="2"/&gt;
   &lt;property name="lastName"     column="ACC_LAST_NAME"  columnIndex="3"/&gt;
  &lt;/result-map&gt;

&lt;mapped-statement name="getAccount" cache-model="account-cache"
result-map="indexed-account-result2"&gt;
   select
     ACC_ID,
     ACC_FIRST_NAME,
     ACC_LAST_NAME
   from ACCOUNT
   where ACC_ID = #value#
 &lt;/mapped-statement&gt;

*************************************
SqlMapConfigExample.java (Don't i have to use the datasource name "basic"
anywhere ?

static
{

   Reader reader =
Resources.getResourceAsReader("examples/sqlmap/maps/SqlMapConfigExample.xml
    </pre>
  </blockquote>
  <pre wrap=""><!---->"
  </pre>
  <blockquote type="cite">
    <pre wrap="">);
   sqlMap = XmlSqlMapBuilder.buildSqlMap(reader);
}

***********************************
QueryForListExample.java

  SqlMap sqlMap = SqlMapConfigExample.getSqlMap();

   try 
   {
      sqlMap.startTransaction();
      Account account = (Account)
sqlMap.executeQueryForObject("getAccount", new Integer(1));
      sqlMap.commitTransaction();
   }
************************************
Sorry about the long email
Santhi
************************************

-----Original Message-----
From: Vic Cekvenich [<a class="moz-txt-link-freetext" href="mailto:[email protected]">mailto:[email protected]</a>]
Sent: Thursday, October 16, 2003 3:49 PM
To: <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
Subject: Re: [MVC-Programmers] IBatis returns null


It's best to use JNDI container DataSource pools, howerver:
&lt;datasource name="ids"
   
factory-class="com.ibatis.db.sqlmap.datasource.SimpleDataSourceFactory" 
default="true"&gt;
&lt;property name="JDBC.Driver" value="org.postgresql.Driver"/&gt;
&lt;property name="JDBC.ConnectionURL" 
value="jdbc:postgresql://localhost:5432/bp?autoReconnect=true"/&gt;
&lt;property name="JDBC.Username" value="bpuser"/&gt;
&lt;property name="JDBC.Password" value="changeme"/&gt;
&lt;/datasource&gt;

aboove is a sample iBatis pool.
I think that was your question. From there, it is just standard iBatis.

.V

Peyathevar, Santhi {PBG} wrote:

 

    </pre>
    <blockquote type="cite">
      <pre wrap="">All:

1.I am trying to use IBatis for running some SQL

   

      </pre>
    </blockquote>
    <pre wrap="">&gt;from simple java code.
 

    </pre>
    <blockquote type="cite">
      <pre wrap="">2.using DbcpDataSourceFactory

3.It connects to the database but the result is null

Can anybody help?

Santhi

_______________________________________________
MVC-Programmers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers">http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers</a>




   

      </pre>
    </blockquote>
    <pre wrap="">_______________________________________________
MVC-Programmers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers">http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers</a>
_______________________________________________
MVC-Programmers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers">http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers</a>


 

    </pre>
  </blockquote>
  <pre wrap=""><!---->
_______________________________________________
MVC-Programmers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers">http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers</a>
_______________________________________________
MVC-Programmers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers">http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers</a>


  </pre>
</blockquote>
</body>
</html>

--------------090802090703050807010609--