I have an .net application that currently uses spring dbprovider to connect to an oracle database.
The database is now being migrated from Oracle to Teradata. I am new to Spring and Teradata does not seem to be in the default list of dbprovider present in Spring.
Is there any way to add the teradata configuration in spring. If so please provide me the step by step method.
Currently this is the connection string being used in Spring .Net:
<db:provider id="dbProvider" provider="OracleClient-2.0" connectionString="Data Source=${db.server};User Id=${db.user};Password=${db.password};" />
I believe it is the data access object for 10g
Could you please let me know how to create a DSN for teradata in Spring .Net Currently I have a DataAccess.xml page with the configuration:
<db:provider id="dbProvider" provider="Teradta" connectionString="Data Source=${db.server};User Id=${db.user};Password=${db.password};" /> - <object id="adoTemplate" type="Spring.Data.Generic.AdoTemplate, Spring.Data"> <property name="DbProvider" ref="dbProvider" /> </object>
You will likely need to install the Teradata ODBC driver, create a DSN, and use the Spring.Net ODBC 1.1 or ODBC 2.0 DBProvider.
EDIT:
The web server will need the DSN created. Whether you use a single 'service' account for the application or individual user accounts (which you will need to provide their credentials in your Spring.Net connection) is a decision for you and/or your company to arrive at.
Related
I found some answers on the problem but none that i could make work in my case. My problem is that I load a datasource from my JBoss configuration with spring:
<xa-datasource jndi-name="java:jboss/jdbc/oracleDatasource" pool-name="jdbc/oracleDatasource" enabled="true">
<xa-datasource-property name="URL">
jdbc:oracle:thin:#URL:1522:SID
</xa-datasource-property>
<xa-datasource-property name="connectionProperties">
v$session.program=MyAPP
</xa-datasource-property>
<driver>oracle-jdbc</driver>
The spring loading is made as follows:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/jdbc/oracleDatasource"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource"/>
</bean>
As you can see, I have set the v$session.program property in JBoss, it works well.
The problem is that i have several applications (war) that can be deployed on the same JBoss server, using this configuration. What I want to do in this case is to have each of my application to have its own name written in the v$session.program property.
So basically, i would like to be able to load the same datasource on each app but to have each of them using its own name to log the program property in oracle DB. Is it possible or do I have to have one datasource for each application hosted?
The only thing you need it to intercept each call of getConnection from connection pool.
You must obtain a real Oracle connection - not a proxy - and call the setClientInfo on 12c or setEndToEndMetrics in older versions to set the action / client / module identification.
An example see here.
Also note that the use of dbms_application_info for this same purpose works as well, but this produces a one server roundtrip too much. The setClientInfo doesn't produce server call, but stores this information for the next statement execution (which is the preformance saving approach).
Also note that to use this feature, your driver must match perfectly with your database - the strange exeptions you can see while setting teh client info are in most cases caused by the incompatibility of teh JDBC driver and the RDBMS.
If putting this information into v$session.module or v$session.client_info is an option, you can do using Java code.
All you need to do is call dbms_application_info.set_module() or dbms_application_info.set_client_info() after your Java code obtained the connection from the datasource.
Something like this:
Connection conn = ... // get connection from the DataSource
CallableStatement cstmt = conn.prepareCall("{call dbms_application_info.set_client_info(?)}");
cstmt.setString(1, "Some interesting information");
cstmt.execute();
I am using Struts and Hibernate 2.0 in my project. My database has changed from oracle 10g to Oracle 11g in my project.
Can you please tell me what changes do I need to make in my Hibernate configuration?
Also Are there any changes required in my Java code.
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:#<host>:<port>:<sid></property>
<property name="connection.username">username</property>
<property name="connection.password">password</property>
<property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">false</property>
</session-factory>
</hibernate-configuration>
Just update driver (Jar file) to Oracle Database 11g Release 2 JDBC Drivers
Your XML doesn't seem like it was configured to Oracle 10g , it shows MySQL..
Anyways do this to solve your question.
Just change the Driver name and URL i.e connection string and also change the Dialect
search for Oracle Dialect online and don't forget to add Jars!!! :)
If your data access logic is implemented in Hibernate then your code is portable. Meaning you really don’t need to change anything specific to database change in your case apart from Driver if its causing any trouble . For instance, if you are changing database from MYSQL to Oracle then probably need to change dialect part, Connection properties of your hibernate configuration file alone plus your database specific driver.
Hope this is helpful!
Yes you need to change the dialect name. Sorry I am posting another answer as I am not able to add another comment.
Find for Oracle11g dialect name online, Dialects are classes that convert HQL(hibernate query language to actually Database query), it may say ClassNotFoundException, if this happens then just search for the Hibernate jar that has Oracle11g Dialect Class in it. As I am pretty sure that this jar is NOT available with the JDBCDriver jars that ORacle provides to connect to database.
The Dialect Jars are a part of Hibernate
I have a HSQL database which Spring automatically creates for me:
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:scheme.sql" /
</jdbc:embedded-database>
And now I want to connect to this database. My question is how to do this, because I don't known which address I should use.
This embedded HSQL database is all-in-memory and in-process, therefore accessible only from the Spring Java process. If you want to access the database from another tool as well, for example to check the contents with a database manager, you can start an HSQLDB server with an all-in-memory instance, then connect to the server from Spring and other tools.
This is covered in the HSQLDB Guide http://hsqldb.org/doc/2.0/guide/listeners-chapt.html
The server is started with this command:
java -cp ../lib/hsqldb.jar org.hsqldb.Server --database.0 mem:test --dbname.0 test
You need to create a Spring data source with username "SA" and password "". The database driver and URL (from the same machine) to configure the Spring data source are:
org.hsqldb.jdbcDriver
jdbc:hsqldb:hsql://localhost/test
I recomend you to use external Database, but just in case if you want to use HSQL, then this may will help you http://java.dzone.com/articles/spring-3-makes-use-embedded-easy
Embedded-database is an in memory DB and Spring supports HSQL, H2, and Derby . You could go to their respective site for the connection details .
For H2 see here .
For HSQL see here and here.
As far as I understand , the
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:scheme.sql" /
</jdbc:embedded-database>
uses an in-memory DB and so is not accessible externally . You'll be able to access this within the same VM and same class loader .
You can connect to the embedded database in the normal fashion, (SQL Developer, SQL Explorer etc); I used my debugger to look at the URL property in the embedded database bean I created with Spring, in your case dataSource. I would think your url would be something along the lines of jdbc:hsqldb:mem:dataSource.
For some people a sufficient solution would be to use the h2 console - as described here:
spring boot default H2 jdbc connection (and H2 console)
You must only remember to set hsqldb drivers where needed. This way the database doesn't have to be started separately. You also don't have to install any additional software to browse it.
you can do like this
final ApplicationContext ctx = new ClassPathXmlApplicationContext("dao-context.xml");
final DataSource dataSource = (DataSource)ctx.getBean("dataSource");
final Connection conn = dataSource.getConnection();
We're using birt 2.6.2 reporting to display reports in our tomcat hosted web app. We have a reporting.rptlibrary file that contains a <data-sources> and <oda-data-source> xml element. Subsequently, all of the report designs reference that reporting.rptlibrary. This is troublesome because everytime I deploy the app, I need to change the reporting.rptlibrary to use the correct jdbc connection info.
Our app is setup so that the connection object is stored in a static field, and the app accesses that field directly during runtime. Is there a way to configure birt to use the connection object that sits in the static field?
I've seen this blog post, and it seems to be the closest to what I'm looking for, but the post was written in 2005, and it's saying I need to create an eclipse plugin, which doesn't seem right for a web app.
I also see some posts about using connection pooling with birt, but we're not using connection pooling.
I am open minded to upgrading to birt 3.7 if it will help with this issue and won't necessitate a large migration effort.
For reports run from Java code, here is the solution working in 2.6.2 and 3.7.0:
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import java.sql.Connection
...
IRunAndRenderTask task; //or IRunTask, when run+render invoked separately
Connection connection;
...
Map<String, Object> appContext = task.getAppContext();
appContext.put("OdaJDBCDriverPassInConnection", connection);
appContext.put("OdaJDBCDriverPassInConnectionCloseAfterUse", false);
task.setAppContext(appContext);
...
task.run()
Connection is passed-in to report and replaces/hides all JDBC connections defined in report design.
try this in xml
<data-sources>
<oda-data-source extensionID="org.eclipse.birt.report.data.oda.jdbc" name="fitupvisualdatasource" id="365">
<list-property name="privateDriverProperties">
<ex-property>
<name>metadataBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
<ex-property>
<name>disabledMetadataBidiFormatStr</name>
</ex-property>
<ex-property>
<name>contentBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
<ex-property>
<name>disabledContentBidiFormatStr</name>
</ex-property>
</list-property>
<property name="odaDriverClass">org.postgresql.Driver</property>
<property name="odaURL">jdbc:postgresql://localhost:5432/acctsql_whs</property>
<property name="odaUser">apoel</property>
<encrypted-property name="odaPassword" encryptionID="base64">cXdlcnR5</encrypted-property>
</oda-data-source>
</data-sources>
The iBatis framework has been significantly tweaked between versions 2 & 3, so much that even the config file (now often referred to as MapperConfig.xml) is different.
That being said, there are lots of examples online on how to create a JDBC connection pool with iBatis, but I couldn't find one example on how to do it with JNDI. There is an updated user guide at: http://svn.apache.org/repos/asf/ibatis/java/ibatis-3/trunk/doc/en/iBATIS-3-User-Guide.pdf which does refer to the JNDI settings on page 19, but I still couldn't it get it correctly communicate with the database.
A working example of a JDNI (container managed connection pool) in iBatis 3 would be greatly appreciated!!
Assuming you've already got a JNDI database resource set up, the following environment for iBatis 3's configuration XML file works for me (running on Tomcat):
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="JNDI">
<property name="data_source" value="java:comp/env/jdbc/webDb"/>
</dataSource>
</environment>
This is what I have in my config file, works well in Glassfish and WebSphere:
<dataSource type="JNDI">
<property name ="data_source" value="jdbc/cpswebmon"/>
</dataSource>
"jdbc/cpswebmon" is the JNDI resource name on my application server