保存进度!
This commit is contained in:
parent
91c99ba8f9
commit
eb7f53ad4b
@ -2,7 +2,7 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-04-22 10:53:49
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-05-05 11:26:35
|
||||
* @LastEditTime: 2022-05-05 17:42:33
|
||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java
|
||||
* @Description: 用来推送公众号消息的程序库。
|
||||
*
|
||||
@ -171,12 +171,11 @@ public class sendMessage
|
||||
* 保存的数据用来判断预警是否已经推送过,以防止反复推送数据。
|
||||
* @param city 城市名称
|
||||
* @param warning 预警数据,为 QWeatherDisasterWarningItem 对象。
|
||||
* @throws SQLException 执行sql时可能抛出的异常。
|
||||
* @throws SQLException 执行sql时可能抛出的异常。出现sql异常,就回滚事务。
|
||||
* @throws IOException 读取数据库配置文件时可能抛出的异常。
|
||||
* @throws ClassNotFoundException 加载oracle jdbc驱动时可能抛出的异常。
|
||||
*/
|
||||
public static void saveWeatherDisasterWarning( String city,
|
||||
QWeatherDisasterWarningItem warning )
|
||||
public static void saveWeatherDisasterWarning( String city, QWeatherDisasterWarning warnings )
|
||||
throws SQLException, IOException, ClassNotFoundException
|
||||
{
|
||||
Connection conn = null;
|
||||
@ -199,21 +198,37 @@ public class sendMessage
|
||||
conn = DriverManager.getConnection( jdbcURL, userName, password );
|
||||
stmt = conn.prepareStatement( sql );
|
||||
|
||||
java.sql.Timestamp pubTime = new java.sql.Timestamp( warning.getPubTime().getTime() );
|
||||
for ( QWeatherDisasterWarningItem warning : warnings.getWarning() )
|
||||
{
|
||||
java.sql.Timestamp pubTime =
|
||||
new java.sql.Timestamp( warning.getPubTime().getTime() );
|
||||
|
||||
stmt.setString( 1, warning.getId() );
|
||||
stmt.setString( 2, warning.getSender() );
|
||||
stmt.setString( 3, city );
|
||||
stmt.setString( 4, warning.getLevel() );
|
||||
stmt.setString( 5, warning.getType() );
|
||||
stmt.setString( 6, warning.getTypeName() );
|
||||
stmt.setString( 7, warning.getTitle() );
|
||||
stmt.setString( 8, warning.getText() );
|
||||
stmt.setTimestamp( 9, pubTime );
|
||||
stmt.setString( 1, warning.getId() );
|
||||
stmt.setString( 2, warning.getSender() );
|
||||
stmt.setString( 3, city );
|
||||
stmt.setString( 4, warning.getLevel() );
|
||||
stmt.setString( 5, warning.getType() );
|
||||
stmt.setString( 6, warning.getTypeName() );
|
||||
stmt.setString( 7, warning.getTitle() );
|
||||
stmt.setString( 8, warning.getText() );
|
||||
stmt.setTimestamp( 9, pubTime );
|
||||
|
||||
stmt.execute();
|
||||
stmt.execute();
|
||||
}
|
||||
|
||||
// 没有问题就提交
|
||||
conn.commit();
|
||||
}
|
||||
catch ( SQLException error )
|
||||
{
|
||||
// 出现sql错误,就回滚!
|
||||
if ( conn != null)
|
||||
{
|
||||
conn.rollback();
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-04-22 10:53:49
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-05-05 11:21:54
|
||||
* @LastEditTime: 2022-05-05 17:53:10
|
||||
* @FilePath: \DisasterWarning\src\test\java\com\cpic\xim\wechat\officalAccount\sendMessageTest.java
|
||||
* @Description:
|
||||
*
|
||||
@ -77,7 +77,7 @@ public class sendMessageTest
|
||||
String city = "东山县";
|
||||
|
||||
|
||||
sendMessage.saveWeatherDisasterWarning( city, warning.getWarning().get( 0 ) );
|
||||
sendMessage.saveWeatherDisasterWarning( city, warning );
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user