title: Adding Database Connections in JSP page in Eclipse
body: <p>I'm trying to add Database connections to my JSP page. I've added this code in a Dynamic Web Project in Eclipse and have tried to run it, but the below code only displays the heading, throwing an error saying "Class Not Found Exception: net.sourceforge.jtds.jdbc.Driver".</p>
  
  <p>To check if there is something wrong with the code I implemented it on a separate java file and it runs successfully there displaying the table values.</p>
  
  <p>Do I need to add a specific jar file? I've added the jtds-1.2.5.jar but still no change.</p>
  
  <pre><code>&lt;body&gt;
  &lt;h3&gt;Database Connections&lt;/h3&gt;
  &lt;%
      Connection connection = null;
      try {
          Class.forName("net.sourceforge.jtds.jdbc.Driver");
  
          connection = DriverManager.getConnection(
                  "jdbc:jtds:sqlserver://&lt;server-name&gt;:&lt;port-number&gt;/&lt;database-name&gt;", "&lt;user&gt;", "&lt;password&gt;");
          String sql = "Select * from &lt;table-name&gt;";
          Statement stmt = null;
          stmt = connection.createStatement();
          ResultSet rs = null;
          rs = stmt.executeQuery(sql);
  %&gt;
  &lt;table&gt;
      &lt;%
          while (rs.next()) {
      %&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;%=rs.getString(2)%&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;%
          }
          } catch (SQLException | ClassNotFoundException e) {
              e.printStackTrace();
              return;
          }
      %&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p></p>
  
  <p>My java File</p>
  
  <pre><code>Class.forName( "net.sourceforge.jtds.jdbc.Driver" );
  
          Conn = DriverManager.getConnection( "jdbc:jtds:sqlserver://&lt;server-name&gt;:&lt;port-number&gt;/&lt;database-name&gt;", "&lt;user&gt;", "&lt;password&gt;");
  
          String sql="SELECT * FROM &lt;table_name&gt;";
  
  
          Statement stmt = Conn.createStatement();
          ResultSet rs = stmt.executeQuery( sql );
  
          while ( rs.next() ) {
  
              String id = rs.getString(1);
                      System.out.println("ID:  "+id);
          } // while  
      } 
      catch ( Exception e ) {
          System.err.println( "Error: " + e.getMessage() );
          e.printStackTrace();
  
          System.exit( -2 );
      } // try-catch
  </code></pre>