Package Tj.test.demo;
Import Java.sql.DriverManager;
Import java.sql.SQLException;
Import java.sql.Statement;
public class Sqlserverconnection {
Public Sqlserverconnection () {
TODO auto-generated Constructor stub
}
public static void Main (String...arg) {
String driver= "Com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url= "jdbc:sqlserver://localhost:1433;databasename=test_01";
String user= "sa", password= "123456"; Here's your sa account password.
try {
Class.forName (driver);
} catch (ClassNotFoundException e) {
SYSTEM.OUT.PRINTLN ("Driver load Failed");
}
Java.sql.Connection Con=null;
try {
Con=drivermanager.getconnection (Url,user,password);
Statement stmt= con.createstatement ();
String a1= "INSERT into TABLE1 VALUES (' 1 ', ' Asahi Brothers ')";
Insert Data SQL statement
Create a table
String a1= "INSERT into USERS VALUES (' 1 ', ' xx ')";
Stmt.executeupdate (A1);//Execute SQL Command object
} catch (SQLException e) {
System.out.println ("Connection failed");
}
if (con!=null) System.out.println ("Connection succeeded:" +con);
}
}
Native SQL Server database connection