
Originally Posted by
Marten Deinum
Please use [ code][/code ] tags when posting code/xml/stacktraces.
Post the code for your dao and some configuration.
Thanks for responding..
Configuration file below:
[code]
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="jdbcDataSource"
class="org.springframework.jdbc.datasource.DriverM anagerDataSource"
p:driverClassName="oracle.jdbc.xa.client.OracleXAD ataSource" p:url="jdbc:oracle:thin:@192.168.2.113:1521:orcl"
p:username="xxxxx" p:password="xxxxx />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
<property name="dataSource" ref="jdbcDataSource" />
</bean>
<bean id="forumDAO" class="com.web.test.JDBCForumDAOImpl">
<property name="dataSource" ref="jdbcDataSource" />
</bean>
</beans>
[/code ]
DAO code below:
Code:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;
public class JDBCForumDAOImpl {
private DataSource dataSource;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public String insertRegistration(String userName) {
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
/**
* Open the connection
*/
connection = dataSource.getConnection();
/**
* Prepare the statement
*/
statement = connection.createStatement();
String sql = "INSERT INTO Registration " + "VALUES ('" + userName +"')";
statement.executeUpdate(sql);
} catch (SQLException e) {
/**
* Handle any exception
*/
e.printStackTrace();
} finally {
try {
/**
* Close the resultSet
*/
if (resultSet != null) {
resultSet.close();
}
/**
* Close the connection
*/
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
/**
* Handle any exception
*/
e.printStackTrace();
}
}
return null;
}
}