java连接Sql2003数据库的封装类如何写 啊

解决方案 »

  1.   

    public class Connecter {
     
    string driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; 
    string URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=huitong"; 
    string username="sa"; 
    string password="dellman";
    Connection connection = null;
      
    try{
     class.forName(driver);
     }
     catch (ClassNotFoundException e)
     {
     e.printStackTrace();
     }
      
    public Connection getConnection()
    {
     try
     {
      connection = DriverManager.getConnection(URL,username,password);
     }
     catch (SQLException e)
     {
      e.printStackTrace();
     }
     return connection;
     }
    }