⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcallablestatement.java

📁 JAVA调用存储过程代码,一个简单的JAVA调用存储过程方法
💻 JAVA
字号:
/**
 * 
 */
package jdbc;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author wlp
 *
 */
public class TestCallableStatement {

	public TestCallableStatement() {
		Connection conn=null;
		CallableStatement cstmt=null;
		String procedure_name="{call pro_stu (?)}";
//		String sql="insert into students(sname,ssex,sage,sdept) values(?,?,?,?)";
		try {
			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
			//注册并载入驱动程序
			conn= DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=FJSE0802","sa","");
			//建立数据库连接
			cstmt=conn.prepareCall(procedure_name);
			//得到一个Statement,通过Statement执行SQL语句得到结果集
			//rs=pstmt.executeQuery("select * from student");
			cstmt.setInt(1,2);		
			cstmt.executeUpdate();
			System.out.println("更新成功!!!");
			
		} catch (ClassNotFoundException e) {
			System.out.println("加载驱动程序错误");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		finally{
			try {
				cstmt.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) {
		new TestCallableStatement();

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -