您的位置:首页 > 家用电器 > 音响 > JDBC中使用数据库的存储过程操作SQL命令

JDBC中使用数据库的存储过程操作SQL命令

luyued 发布于 2011-02-02 07:01   浏览 N 次  

import java.sql.*;

public class exp

{

static String sqlstr,title_id,title;

static Connection con;

static Statement stmt;

static ResultSet rs = null;

public static void main(String[] args) throws Exception

{

String url = "jdbc:odbc:pubs";

String strProc;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con = DriverManager.getConnection(url,"sa","");

stmt = con.createStatement();

try

{

strProc = "create procedure showtitles as select * from titles";

stmt.executeUpdate(strProc);

}

catch(Exception e){}

CallableStatement cs = con.prepareCall("{call showtitles}");

rs = cs.executeQuery();

showrecord();

rs.close();

stmt.close();

con.close();

}

static void showrecord() throws Exception

{

while (rs.next())

{

title_id = rs.getString(1);

title = rs.getString(2);

图文资讯
广告赞助商