RicardoPereira
Programmer
Hi,
I'am using a class to access from a jsp page to an sql server 2000 database. I think i must include in the code below something to close the connection after de execution of the code. What do i need to include ? Anyone could help me ?
import java.sql.*;
import java.lang.*;
import java.util.ArrayList;
import xpto.*;
public class AccessDB {
Connection con;
static {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch( ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
}
public AccessDB() throws SQLException {
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://server:1433;User=***;Password=***;DatabaseName=Test;");
}
public ArrayList getAuth(String username, String password) throws SQLException {
ArrayList res=new ArrayList();
PreparedStatement pstmt=
con.prepareStatement("exec Extranet_permission'" + username + "', '" + password + "'");
ResultSet rslt=pstmt.executeQuery();
while (rslt.next()) {
res.add(new xpto.TblUsers (rslt.getString(1)) );
}
return res;
}
}
I'am using a class to access from a jsp page to an sql server 2000 database. I think i must include in the code below something to close the connection after de execution of the code. What do i need to include ? Anyone could help me ?
import java.sql.*;
import java.lang.*;
import java.util.ArrayList;
import xpto.*;
public class AccessDB {
Connection con;
static {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch( ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
}
public AccessDB() throws SQLException {
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://server:1433;User=***;Password=***;DatabaseName=Test;");
}
public ArrayList getAuth(String username, String password) throws SQLException {
ArrayList res=new ArrayList();
PreparedStatement pstmt=
con.prepareStatement("exec Extranet_permission'" + username + "', '" + password + "'");
ResultSet rslt=pstmt.executeQuery();
while (rslt.next()) {
res.add(new xpto.TblUsers (rslt.getString(1)) );
}
return res;
}
}