日期:2014-05-17 浏览次数:20760 次
public class DB {
private Connection con;
private String url = "jdbc:sqlserver://localhost:1433; DatabaseName=work_week";
private String user = "sa";
private String password = "picc9518";
public DB(){
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
this.con=DriverManager.getConnection(url,user,password);
}
catch(SQLException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("forName wrong~~~~~");
}
}
public Connection getConnection() {
return this.con;
}
public void closed(){
try{
if(con!=null)
con.close();
}
catch(Exception e){
e.printStackTrace();
}
}
DB db=new DB();
try{
db.getConnection();
System.out.println("as11111adf");
}
catch(Exception ex){
ex.printStackTrace();
System.out.println("Wrong");
}
System.out.println("asdfsadf");
try{
DB db=new DB();
conn=db.getConnection();
stmt=conn.prepareCall("{call sp_check_user (?,?)}");
stmt.setString(1, userName);
stmt.setString(2, passWord);
stmt.registerOutParameter(3, java.sql.Types.INTEGER);
stmt.execute();
result=stmt.getInt(1);
}