I am trying to create a calss with a constructior that creates connection with MYSql database , i am using database name as dbetch . I have set the path varable but still it id throwing error

package login;
import java.sql.*;
import java.sql.DriverManager;
import com.mysql.jdbc.Connection;
public class conn {
 Connection con=null;
 ResultSet rs=null;
 Statement st=null;

 public conn() {
  Class.forName("com.mysql.jdbc.Driver");

  con=DriverManager.getConnection("jdbc:mysql://localhost/dbetech","root","");
 }
}

Error thrown

D:\etech\WEB-INF\src>javac *.java
conn.java:18: incompatible types
found   : java.sql.Connection
required: com.mysql.jdbc.Connection
                con=DriverManager.getConnection("jdbc:mysql:///dbetech","root","");

1 error

Recommended Answers

All 3 Replies

Sorry but i am suing follwoing line to craete connection-:

con=DriverManager.getConnection("jdbc:mysql:///dbetech","root","");

Use java.sql.Connection for your "con" variable type. Just change the import type and it will be fine.

Hey......... it worked for me...thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.