📄 smsdao.java
字号:
package test.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import test.send.ListenTask;
import test.send.SendMessageEntity;
public class SmsDAO
{
//将接收到的短信内容插入数据库
public void insertNotifySms(String notifMessage,String senderAddress,String linkId,String productId,String spId,String spPassword)
{
Connection conn = ConnJDBC.getConnection();
PreparedStatement pstmt = null;
try
{
String sql = "insert into notifMessage values(?,?,?,?,?,?)" ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, notifMessage);
pstmt.setString(2, senderAddress);
pstmt.setString(3, linkId);
pstmt.setString(4, productId);
pstmt.setString(5, spId);
pstmt.setString(6, spPassword);
pstmt.execute();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(pstmt!=null)
{
try
{
pstmt.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
//发送短信返回的状态报告存入数据库
public void insertDelivery(String correlator,String address, String deliveryStatus)
{
Connection conn = ConnJDBC.getConnection();
PreparedStatement pstmt = null;
try
{
String sql = "insert into deliveryStatus values(?,?,?)" ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, correlator);
pstmt.setString(2, address);
pstmt.setString(3, deliveryStatus);
pstmt.execute();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(pstmt!=null)
{
try
{
pstmt.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
//执行业务通知消息
public void serviceConsumeNotify(String streamingNo,String productID,String userID,int userIdType,String linkID,String featureStr)
{
Connection conn = ConnJDBC.getConnection();
PreparedStatement pstmt = null;
try
{
String sql = "insert into serviceConsume values(?,?,?,?,?,?)" ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, streamingNo);
pstmt.setString(2, productID);
pstmt.setString(3, userID);
pstmt.setInt(4, userIdType);
pstmt.setString(5, linkID);
pstmt.setString(6, featureStr);
pstmt.execute();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(pstmt!=null)
{
try
{
pstmt.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
//订购消息更新消息存入数据库
public void orderUpdate(String streamingNo,String productID,String packageID,String userID,int userIDType,int OPType)
{
Connection conn = ConnJDBC.getConnection();
PreparedStatement pstmt = null;
try
{
String sql = "insert into orderUpdateNotify values(?,?,?,?,?,?)" ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, streamingNo);
pstmt.setString(2, productID);
pstmt.setString(3, packageID);
pstmt.setString(4, userID);
pstmt.setInt(5, userIDType);
pstmt.setInt(6, OPType);
pstmt.execute();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(pstmt!=null)
{
try
{
pstmt.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
//管理信息更新存入数据库
public void notifyManagementInfo(String streamingNo,String ID,int status,int IDType)
{
Connection conn = ConnJDBC.getConnection();
PreparedStatement pstmt = null;
try
{
String sql = "insert into notifyManagementInfo values(?,?,?,?)" ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, streamingNo);
pstmt.setString(2, ID);
pstmt.setInt(3, status);
pstmt.setInt(4, IDType);
pstmt.execute();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(pstmt!=null)
{
try
{
pstmt.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
//查询短信任务
public SendMessageEntity selectSms()
{
Connection conn = ConnJDBC.getConnection();
PreparedStatement pstmt = null;
ResultSet rs = null;
SendMessageEntity sendMessageEntity = null;
try
{
String sql = "select top 1 * from sendSms where status = 0 order by insertDate " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next())
{
sendMessageEntity = new SendMessageEntity();
sendMessageEntity.setSmsID(rs.getInt("SMSID"));
sendMessageEntity.setAddresse(rs.getString("addresses"));
sendMessageEntity.setCharging(rs.getString("charging"));
sendMessageEntity.setFeecode(rs.getString("feecode"));
sendMessageEntity.setLinkId(rs.getString("linkId"));
sendMessageEntity.setMessage(rs.getString("message"));
sendMessageEntity.setProductId(rs.getString("productId"));
sendMessageEntity.setSAN(rs.getString("SAN"));
sendMessageEntity.setSenderAddress(rs.getString("senderAddress"));
sendMessageEntity.setSmsURL(rs.getString("smsURL"));
sendMessageEntity.setSpId(rs.getString("spId"));
sendMessageEntity.setSpPassword(rs.getString("spPassword"));
}
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(rs!=null)
{
try
{
rs.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(pstmt!=null)
{
try
{
pstmt.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return sendMessageEntity;
}
//修改短信状态
public void updateStatus(int smsID)
{
Connection conn = ConnJDBC.getConnection();
PreparedStatement pstmt = null;
try
{
String sql = "update sendSms set status = 1 where SMSID = ?" ;
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, smsID);
pstmt.execute();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(pstmt!=null)
{
try
{
pstmt.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -