数据源连接SQL server (调用的是存储过程)

 

和前面的

数据源连接SQL server 文章中区别就在于dao层,其它的都一样

 

dao:

 

 

package com.wdpc.wlw.admin.dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Date;
import java.sql.SQLException;
import java.util.List;

import javax.xml.crypto.Data;



import com.wdpc.wlw.admin.model.AdminInserNewsModel;
import com.wdpc.wlw.commons.DbManager;



public class AdminInserNewsDao {
		public int inserNews(String title,String newsContext,int typeid ){
			Connection conn = DbManager.getConnection();
			//区别就在这里!!
			CallableStatement proc =null;
			int state = 0  ;
			try {
			    //AddNewsByTypePRO 这是自己写的存储过程的名字!
				proc =conn.prepareCall("{Call AddNewsByTypePRO(?,?,?)}");
				proc.setString(1, title);
				proc.setString(2, newsContext);
				proc.setInt(3, typeid);				 
				state =proc.executeUpdate();
				 
			} catch (SQLException e){				 
				e.printStackTrace();
			} finally {
				try {
					 
					if (proc != null) {
						proc.close();
					}
					if (conn != null) {
						conn.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			
			return state;			
		}
}

 

 

 

你可能感兴趣的:(java,DAO,sql,xml,SQL Server)