我在理解我在做什么错误或缺少一些基本的东西时遇到了很多困难。我在一天左右的时间里搜索了我的问题,并没有理解我错过了什么。创建一个测试连接到SQL Server的Junit测试
所以我想要做的是创建一个JUnit测试,连接到我的SQL服务器并执行查询以获取当前时间。我与服务器的连接正常工作,并且已经在服务器上的Query中测试了我的SQL代码,并且完美地工作。出于某种原因,测试不发送我的代码,并得到任何东西回来..不知道什么香港专业教育学院做了错事的,如果这是这种形式(小新本)过于粗放
@Override
public Timestamp PCNow() throws PCSQLException {
//SQL Server uses GETDATAE
String strSQL = "SELECT GETDATE()";;
try {
//Get a result set with the timestamp field
Timestamp datTs = (Timestamp)jdbcTemplate.queryForObject(strSQL, Timestamp.class);
//Make sure there is a result
if (datTs == null)
//Throw an exception indicating the server could not give a time
throw new PCSQLException("UNABLE_SERVER_TIME");
return datTs;
}
catch (Exception e) {
throw new PCSQLException("This didn't work PCNow", e);
}
}
这是我的测试类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-sql.xml"})
//instantiate TestExecutionListener class
@TestExecutionListeners
public class ConnectionAdapterSQLTest {
@Autowired
ConnectionAdapterImpl connectionAdapterPC;
private final Log log = LogFactory.getLog(getClass());
@Before
public void setUp() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public final void testPCNow() {
log.info("testPCNow()");
//fail("Not yet implemented");
}
的applicationContext-sql.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- connection to Sql Server using JDBC sqljdbc4.2 -->
<bean id="dataSourcePC" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://******;databaseName=******" />
<property name="username" value="******" />
<property name="password" value="******" />
</bean>
<bean id="connectionAdapterPC"
class="com.*******.*******.connections.ConnectionAdapterSQL">
<property name="dataSource" ref="dataSourcePC" />
<property name="useConnectionPool" value="false" />
</bean>
<bean id="dxDateTimeFormatter" class="com.*******.*******.data.format.DateTimeFormatter">
<property name="dateFormat" value="dd-MMM-yyyy" />
</bean>
</beans>
你可以将'applicationContext-sql.xml'添加到问题中吗? –