0

I used to work in all my projects with MySQL.

But now I should develop a web application using JEE and SQL Server? Can we do it? If yes, what should I change in this connection part:

public class gestion extends HttpServlet {
    private static final long serialVersionUID = 1L;
     String urlPilote="com.mysql.cj.jdbc.Driver";//chemin pr xarger le pilote
        String urlBaseDonnees="jdbc:mysql://localhost/lydec?serverTimezone=UTC";//chemin de connexion a la bd
        Connection con=null; 

    public gestion() {
        super();        // TODO Auto-generated constructor stub
    }       

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out =response.getWriter();
        try {
            Class.forName(urlPilote);
            con=DriverManager.getConnection(urlBaseDonnees, "root", "");
            String sql="select * from poste ";
            PreparedStatement ps=con.prepareStatement(sql);
            ResultSet rs=ps.executeQuery();


    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
jarlh
  • 42,561
  • 8
  • 45
  • 63
imanealami
  • 189
  • 5
  • 13
  • Does this answer your question? [How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib](https://stackoverflow.com/questions/6792197/how-to-add-jar-libraries-to-war-project-without-facing-java-lang-classnotfoundex) – BalusC Feb 16 '20 at 12:29

1 Answers1

0

It's better idea to configure application server to open connection for you. Application server will manage the connection pool, lifecycle etc.

for jboss: How can we configure database connection from JBOSS?

Lonestar
  • 51
  • 6