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 department 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;
}
}
SQL Server Connection