首页 > 代码库 > JDBC的连接和操作
JDBC的连接和操作
package Test;
import java.sql.*;
public class Test21 {
public static void main(String[] args) {
Connection con=null;
Statement sta=null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;database=stuDB","sa","123456");
sta=con.createStatement();
String sql="insert useinfo values(1,‘2‘,‘3‘)";
int result=sta.executeUpdate(sql);
System.out.println("ccc");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
JDBC的连接和操作