I am calling this constructor but it is not getting complied

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

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

throwing error message:

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

Recommended Answers

All 2 Replies

this has nothing to do with JSP...

And you seem to have defined your instance (I hope) variable conn as being of the wrong type.

Anyway, what you're doing is terrible. You should never open connections to external resources at a different place from where you're going to close them.
Doing so is a recipe for disaster.

Hi

Yes it has nothing to do JSP but since its part of Core java and it is used for bussiness loin i put it here.

and i modified the code and it worked for me ,,this is modified code -:

public class conn {

Connection con=null;
ResultSet rs=null;
Statement st=null;

public conn()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql:///dbetech","root","");
}
catch (Exception e) {
System.out.println(e);
}
}
}

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.