|
Error:500
Internal Servlet Error:
javax.servlet.ServletException: Cannot create bean of class count.accessdata
The above error says that your bean can not be instantiated. The most possible reason is that you did not import the Class "accessdata" in your JSP page. your should import the class will the full package name at the beginning of the JSp page.
From your question, I think you have little knowledge of Java. Because you even do not know what "import oracle.jdbc.driver.*;" means, and trying to use "mysql.jdbc.driver.*:".
I do not think the hongtao's code will work. Because what Yiben is using is MySQL, but you are using borland DataSource. I suppose hongta is using Weblogic as App Server. But I do not think Yiren is using Weblogic. It is impossible for a company using MySQL to use Weblogic, which is very expensive. What Yiben's company is using must be IPlanet or Tomcat, or inbeded servlet engine such as JServer.
Yiben, You should do following:
1. Make sure you have downloaded the MySQL's jdbc driver package, and have put its path in the classpath.
2. Write a bean class like following:
package db;
import java.sql.*;
import org.gjt.mm.mysql.*;
public class DbAccess{
public Connection getConnection(){
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:mysql:*****";//replace ***** with your real db URL
String dbUsrId = "yourID";
String dbPassword = "yourPW";
Connection conn = null;
try{
Class.forName(driver);
conn = DriverManager.getConnection(url,dbUsrId,dbPassword);
return conn;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
}
3. write a standalone application to test the JavaBean first. Just as following:
package ***; //the same package as your db bean
import java.sql.*;
public class DbBeanTest{
public static void main(String args[]){
DbAccess dbBean = new DbAccess();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
conn = dbBean.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from tab");//I do not know what table you have in your database, so I just select all tables name out in your database.
while(rs.next()){
System.out.println(re.getString(1));//just print out the table name
}
}catch(Exception e){
e.printStackTrace()
}
finally{
try{
if(rs != null) rs.close();
if(stmt != null) stmt.close(();
if(conn != null) conn.close();
}
catch(Exception e){}
}
}
}
4. If the above test class runs well, begin to use the bean in the JSP
5. check wether you have imported the class in your JSP.
I write it directly in the web without test. But I think the above class should have no problem.
Good lucky! |
|