DeleteJDBC.java~2~
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- package com.cwj.DatabaseAccessDemo;
- import java.sql.*;
- public class DeleteJDBC {
- public DeleteJDBC(){
- ResultSet result;
- try{
- Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
- Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1;DatabaseName=Northwind;User=sa;Password=sa");
- Statement stat1=conn.createStatement();
- Statement stat2=conn.createStatement();
- String sqlString="delete customers where CustomerID='ZKRJ'";
- stat1.execute(sqlString);
- //下面语句检查刚才修改的记录
- result=stat2.executeQuery("Select * from customers where CustomerID='ZKRJ'");
- System.out.println("检查记录是否存在:");
- System.out.println("客户ID"+" "+"公司名称"+" "+"联系人姓名");
- while(result.next()){
- System.out.println(result.getString(1)+" "+result.getString(2)+" "+result.getString(3));
- }
- }catch(Exception e){
- System.out.println("Error"+e);
- }
- }
- }