关于sql server 2005存储过程的写法分分快三全天计

作者:分分快三全天计划网站

//查询结果
rs = call.executeQuery();

String sqlString="update bookPhone set ph_name=?,ph_sex=?,ph_age=? where ph_name=?";

// 初始化数据库连接参数
public static Connection getConnection() throws SQLException {
// 初始化变量
Connection con = null;
String url = "jdbc:sqlserver://localhost:1433;databasename=CMCF_qqqqqqqk";
String userName = "sa";
String password = "wang";

 

            CREATE PROCEDURE [dbo].[get]
              @hyzk varchar(255),
              @feibie varchar(255)
            AS
            BEGIN
              SELECT hyzk,feibie,sysID,updateTime,chuanghao,ksmc FROM BingRenYiLan
              WHERE hyzk=@hyzk AND feibie =@feibie
            END

Statement stmt=conn.createStatement();

//设置参数
call.setString(1, "已婚");
call.setString(2, "自费");

e.printStackTrace();

// 连接url
try {
// 加载数据库驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(url, userName, password);
} catch (SQLException e) {
con.close();
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

       b.(java后台调用sql server存储过程):

static PhoneBook requestByName(String name){

        

ps=conn.prepareStatement(sqlString);

//遍历
while (rs.next()) {
System.out.println("婚姻状况(hyzk):" rs.getString(1));
System.out.println("费别(feibie):" rs.getString(2));
System.out.println("主键(sysID):" rs.getString(3));
System.out.println("更新时间(updateTime):" rs.getString(4));
System.out.println("床号(chuanghao):" rs.getString(5));
System.out.println("科室名称(ksmc):" rs.getString(6));
// System.out.println();
}
}

}

        实例:

import java.sql.SQLException;

//测试        

PreparedStatement ps=null;

        a.(数据库端)   

}

打开数据库的SQL Server Managerment Studio---->数据库----->打开数据库会看见"可编程行"------->打开有存储过程------->新建存储过程

String sqlString="insert into bookPhone(ph_name,ph_sex,ph_age)"

public static void main(String[] args) throws SQLException {
Connection con = null;
ResultSet rs = null;
// 调用数据库连接
con = getConnection();
//调用存储过程的语句-------------------
SQLServerCallableStatement call = (SQLServerCallableStatement) con
.prepareCall("{call get(?,?)}");

ps.setString(1,name);

e.printStackTrace();

try{

}

1.

String sex=pb.getSex();

conn.close();

}

import java.sql.PreparedStatement;

stmt.executeUpdate(sqlString);

try{

PhoneBook pb2=new PhoneBook("王小毛","男","14");

e.printStackTrace();

Statement stmt=conn.createStatement();

"values(" "'" name "','" sex "','" age "')";

}

}

}

try{

public class JdbcDemo {

e.printStackTrace();

PhoneBook pb1=new PhoneBook("王大毛","男","14");

e.printStackTrace();

delete("王大毛");

}

static void insert(){

}

}catch(SQLException e){

PreparedStatement ps=null;

Statement stmt=conn.createStatement();

Connection conn=DriverManager.getConnection(URL,user,password);

conn.close();

e.printStackTrace();

private final static String user = "sa";

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

conn.close();

e.printStackTrace();

PreparedStatement ps=null;

update(pb,"李狗蛋");

}catch(ClassNotFoundException e){

static void request(){

while(rs.next()){

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

import java.sql.SQLException;

conn = DriverManager.getConnection(URL, user, password);

ps.setString(2,pb.getSex());

try{

conn.close();

conn.close();

}catch(ClassNotFoundException e){

}

}

import java.sql.DriverManager;

 

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

e.printStackTrace();

public static void main(String[] args) {

stmt.executeUpdate(sqlString);

}catch (SQLException e) {

}catch(ClassNotFoundException e){

private final static String URL="jdbc:sqlserver://localhost:1433;database=BookPhone";

stmt.executeUpdate(sqlString);

ps.executeUpdate();

ps=conn.prepareStatement(sqlString);

sql server中已建立BookPhone数据库,包含bookPhone表,eclipse中有BookPhone类,三个string类型的值

}catch(ClassNotFoundException e){

ps.setString(1,pb.getName());

}catch(ClassNotFoundException e){

}

e.printStackTrace();

stmt.close();

String age=pb.getAge();

}

String sqlString="delete bookPhone where ph_name=?";

ps.setString(4,oldname);

PhoneBook pb=null;

 

e.printStackTrace();

conn = DriverManager.getConnection(URL, user, password);

ps.setString(1,name);

static void update(PhoneBook pb,String oldname){

PreparedStatement ps=null;

String sqlString="select * from bookPhone where ph_name=?";

// TODO Auto-generated catch block

private final static String password="123456";

System.out.print(rs.getString(3));

private final static String user="sa";

Connection conn=null;

// TODO Auto-generated catch block

pb.setSex(rs.getString(2));

Connection conn=DriverManager.getConnection(URL,user,password);

ps.setString(2,pb.getSex());

try{

ps.executeUpdate();

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

import java.sql.ResultSet;

Connection conn=DriverManager.getConnection(URL,user,password);

}

}catch (SQLException e) {

ps.close();

e.printStackTrace();

static void update(PhoneBook pb,String oldName){

conn.close();

PhoneBook pb=new PhoneBook("李小狗蛋","男","12");

}catch(SQLException e){

pb.setName(rs.getString(1));

System.out.println(rs.getString(3));

e.printStackTrace();

}

}

}

System.out.print(rs.getString(2) ",");

import java.sql.Connection;

import java.sql.ResultSet;

String sqlString="delete bookPhone where ph_name='" name "'";

String sqlString="select * from bookPhone";

pb.setAge(rs.getString(3));

}

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

Connection conn=DriverManager.getConnection(URL,user,password);

String sex="男";

e.printStackTrace();

static void insert(PhoneBook pb){

while(rs.next()){

String sqlString="insert into bookPhone(ph_name,ph_sex,ph_age) values(?,?,?)";

request();

static void delete(String name){

ResultSet rs=stmt.executeQuery(sqlString);

public class jdbcDemo01 {

System.out.println(requestByName("王大毛"));

String name="李狗蛋";

insert(pb1);

 

}catch(ClassNotFoundException e){

String sqlString="update bookPhone set ph_name='" name "',ph_sex='" sex "',ph_age='" age "' where ph_name='" oldName "'";

try{

private final static String password = "123456";

insert();

String name=pb.getName();

rs.close();

 2.

}catch (SQLException e) {

import java.sql.Statement;

ps.close();

ps=conn.prepareStatement(sqlString);

String age="12";

System.out.println();

}

}

conn.close();

try{

Connection conn=null;

// TODO Auto-generated catch block

ps.setString(1,pb.getName());

e.printStackTrace();

private final static String URL = "jdbc:sqlserver://127.0.0.1:1433;databasename=BookPhone";

ps.close();

import java.sql.Connection;

Connection conn=null;

ps.setString(3,pb.getAge());

public static void main(String[] args) {

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

pb=new PhoneBook();

delete("barry55");

ps=conn.prepareStatement(sqlString);

}catch(ClassNotFoundException e){

stmt.close();

conn.close();

stmt.close();

ps.executeUpdate();

System.out.print(rs.getString(2) ",");

ps.setString(3,pb.getAge());

}catch(SQLException e){

ResultSet rs=ps.executeQuery();

try{

conn = DriverManager.getConnection(URL, user, password);

Statement stmt=conn.createStatement();

Connection conn=null;

// TODO Auto-generated catch block

conn = DriverManager.getConnection(URL, user, password);

}

import java.sql.DriverManager;

 

ps.close();

System.out.print(rs.getString(1) ",");

return pb;

}

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

}catch(ClassNotFoundException e){

}catch(SQLException e){

stmt.close();

}catch (SQLException e) {

e.printStackTrace();

Statement和prepareStatement

static void delete(String name){

e.printStackTrace();

本文由分分快三计划发布,转载请注明来源

关键词: 分分快三计划 Java基础