sqlserver 连接

package demosql;
import java.sql.*;
public class test {
 static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
 static final String URL = "jdbc:sqlserver://localhost:1433;databaseName=test";
 static final String USER = "su";
 static final String PWD = "zhang";
 static Statement sm = null;
 static Connection con = null; 
 public static void main(String args[]){
  
  try {   
   Class.forName(DRIVER);   
   con = DriverManager.getConnection(URL, USER,PWD);
   Statement sm = con.createStatement();
   int i = sm.executeUpdate("insert into 部门  values(4,'yyy')");
   if(i == 1)
    System.out.println("Success");
   else
    System.out.println("Fail");
   
   } catch (ClassNotFoundException e) {   
    // TODO Auto-generated catch block  
    e.printStackTrace();
    System.out.println("not found");}
  catch (SQLException e) {   
   // TODO Auto-generated catch block  
   e.printStackTrace();  } 
  finally{
   if(sm != null)
    try {
     sm.close();
    } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   if(con != null)
    try {
     con.close();
    } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
  }
 // return con;
  }
 }



你可能感兴趣的:(localhost,sqlserver,package)