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;
}
}
sqlserver 连接
原创
©著作权归作者所有:来自51CTO博客作者雪然天堂的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:sqlserver
下一篇:java 树与表心得
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MySQL、SQLserver连接
sql,mysql
mysql sql