租房买房买生意上iU91
楼主: Yiben
打印 上一主题 下一主题

[电脑] JavaBean Expert Help!!!

[复制链接]   [推荐给好友]
21#
 楼主| 发表于 2002-7-12 11:27 | 只看该作者
ifyou, thank you very much, how about the JSP file, do I need change some thing?

I'm compiling the java program now.
回复 支持 反对

使用道具 举报

22#
 楼主| 发表于 2002-7-12 11:32 | 只看该作者
Hi, ifyou, I upload the new class and it still doesn't work, it give me the same error message
回复 支持 反对

使用道具 举报

23#
发表于 2002-7-12 11:32 | 只看该作者
I already changed the jsp too
回复 支持 反对

使用道具 举报

24#
 楼主| 发表于 2002-7-12 11:37 | 只看该作者
I can't find the JSP file, could you please send it again?
回复 支持 反对

使用道具 举报

25#
发表于 2002-7-12 13:20 | 只看该作者
check your email.
回复 支持 反对

使用道具 举报

26#
发表于 2002-7-12 16:03 | 只看该作者
hi,maybe i can give you some help.
email:jingyuan72@sina.com.cn
回复 支持 反对

使用道具 举报

27#
发表于 2002-7-12 16:05 | 只看该作者
oh,send me your program if you like, maybei can help you.
jingyuan72@sina.com.cn
回复 支持 反对

使用道具 举报

28#
 楼主| 发表于 2002-7-13 13:01 | 只看该作者
ifyou, 我看到了jsp文件但是那个错误还是同样的, 还是不行. 但仍很感谢你.
回复 支持 反对

使用道具 举报

29#
发表于 2002-7-14 09:52 | 只看该作者
My Code:
  protected String

    // Borland JDataStore
    driver = "com.borland.datastore.jdbc.DataStoreDriver",
    db = "jdbc:borland:dsremote://localhost/db/agent.jds",

    // postgreSQL
    // driver = "org.postgresql.Driver",
    // db = "jdbc:postgresql://localhost/pla",

    // mySQL
    // driver = "org.gjt.mm.mysql.Driver",
    // db = "jdbc:mysql://localhost/pla",

    user = "sa",
    password = "sa";

  protected Connection conn = null;
  protected boolean updatable = false;

  // constructor
  public DBA() throws Exception {
    Class.forName(this.driver).newInstance();
    this.conn = DriverManager.getConnection(this.db, this.user, this.password);

    // the way in J2EE, dbName must be register in the J2EE server.
    // this.conn = ((DataSource) new InitialContext().lookup(dbName)).getConnection();
  }
回复 支持 反对

使用道具 举报

30#
发表于 2002-7-15 21:27 | 只看该作者
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!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

Copyright © 1999 - 2024 by Sinoquebec Media Inc. All Rights Reserved 未经许可不得摘抄  |  GMT-5, 2024-11-24 10:08 , Processed in 0.051955 second(s), 38 queries .