title: connect to DB java - the import java sql connection conflicts with a type defined in the same file
body: <p>I tried to connect to database using jdbc, but I have still error next to <code>import java.sql.Connection;</code></p>
  
  <blockquote>
    <p>The import java sql connection conflicts with a type defined in the
    same file</p>
  </blockquote>
  
  <p>I have <code>mysql-connector-java-5.1.40-bin.jar</code> kept in Apache Tomcat Library. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>package demo;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * Servlet implementation class Connect
   */
  @WebServlet("/Connect")
  public class Connection extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public Connection() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
       *      response)
       */
      protected void doGet(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
  
          PrintWriter out = response.getWriter();
  
          try {
              Class.forName("com.mysql.jdbc.Driver");
          } catch (ClassNotFoundException e) {
              out.println("Can't load database driver");
              //e.printStackTrace();
              String strClassPath = System.getProperty("java.class.path");
  
              System.out.println("Classpath is " + strClassPath);
              return;
          }
  
          Connection conn = null;
  
          try {
              conn = DriverManager.getConnection(
                      "jdbc:mysql://localhost:3306/webshop", "root", "root");
          } catch (SQLException e) {
              out.println("Can't connect to database.");
              return;
          }
  
          out.println("Connected to database.");
  
          try {
              conn.close();
          } catch (SQLException e) {
  
          }
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
       *      response)
       */
      protected void doPost(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
      }
  
  }
  </code></pre>