补充点:我的配置  2000专业系统+jakarta-tomcat-5.0.16+JDK1.2.2

解决方案 »

  1.   

    連接池配置如下:
    -->
    <datasources>
    <local-tx-datasource>
    <jndi-name>jdbc/mysql</jndi-name>
    <connection-url>jdbc:mysql://localhost:3306/mysql</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password/>
    </local-tx-datasource>
    </datasources>
      

  2.   

    private static DataSource ds;
    private static boolean nFirstTime=true;
    private Connection conn;
    try
        {
         Context initCtx = new javax.naming.InitialContext();
              ds =(DataSource)initCtx.lookup(HttpParams.getString(Constants.DATASOURCE));          
        }       
        catch (NamingException e)
        {
         log.error(e.getMessage());
        }  try
    {
          conn=ds.getConnection();
    }
        catch(Exception exp )
        {
         log.error(exp.getMessage());
        }
      

  3.   

    public  ResultSet executeQuery(String sql)
     {
    Statement stmt;
    ResultSet rst;
        rst = null;     
        try
        {
          stmt=conn.createStatement();
          rst = stmt.executeQuery(sql);
        }
        catch(SQLException ex)
        {
         log.error("Query error:"+sql);
        }
        return rst;
     }public  void executeUpdate(String sql) throws SQLException
    {
    Statement stmt;
    ResultSet rst;
        try
        {    
          stmt=conn.createStatement();       
          stmt.executeUpdate(sql);
          stmt.close();       
        }
        catch(SQLException ex)
        {
           log.error("Update error:"+sql);
           throw ex;
        }
    }
      

  4.   

    特别是关于中文部分"jdbc:mysql://localhost/flyfoxssql?user=flyfoxssql&password=flyfoxssql&useUnicode=false&characterEncoding=8859_1" ;上面的useUnicode=false中的false和true有什么区别,不是理论上的,最好结合实际,也就是在什么情况下用false,什么情况下用false.还有,我用characterEncoding=8859_1存取一切正常,但修改为gb2312后却有点不正常!
      

  5.   

    你是用jsp的代码直接连吗,
    还是用xml来设置连接
      

  6.   

    package JDBCBean;import java.sql.*;
    import java.io.*;
    import java.util.*;public class JdbcBean{
    private String driver="sun.odbc.JdbcOdcDriver";
        private String url="jdbc:odbc:chatroom";
        private String query="";             //查询的SQL命令
        private String sql="";
        
        private Connection connection=null;
        private Statement statement=null;
        private ResultSet rs=null;
        
       // public JdbcBean(){}
        public JdbcBean(){
         try{
             Class.forName(driver);
             
         }
         catch(ClassNotFoundException cnfe){
             System.out.println("Message:"+cnfe.getMessage() );
         }
        
         catch(Exception ex){
             ex.printStackTrace();
         }
        
        
        }
        public ResultSet getRs(String query){     //执行查询命令,得到一个结果集
         try{
             connection=DriverManager.getConnection(url,"sa","");
             Statement statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
             ResultSet rs=statement.executeQuery(query);
             
             
         }
         catch(SQLException ex){
             System.out.println("\nERROR:---- SQLException ----\n");
             while(ex!=null){
                 System.out.println("Message: "+ex.getMessage());
                 System.out.println("SQLState: "+ex.getSQLState());
                 System.out.println("ErrorCode: "+ex.getErrorCode());
                 ex=ex.getNextException();
             }
         }
         catch(Exception ex){
             ex.printStackTrace();
         }
         finally{
             try{
                 if(statement !=null){  statement.close();   }
                 if(connection !=null){   statement.close();  }
             }
             
            catch(SQLException ex){
             System.out.println("\nERROR:---- SQLException ----\n");
             while(ex!=null){
                 System.out.println("Message: "+ex.getMessage());
                 System.out.println("SQLState: "+ex.getSQLState());
                 System.out.println("ErrorCode: "+ex.getErrorCode());
                 ex=ex.getNextException();
             }
            } 
        
         }
         return rs;
        }
        public void update(String sql){              //执行一个更新命令,实行对数据的删除,修改和插入
            try{
             connection=DriverManager.getConnection(url,"sa","");
             Statement statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
             statement.executeUpdate(sql);
            }
            catch(SQLException ex){
             System.out.println("\nERROR:---- SQLException ----\n");
             while(ex!=null){
                 System.out.println("Message: "+ex.getMessage());
                 System.out.println("SQLState: "+ex.getSQLState());
                 System.out.println("ErrorCode: "+ex.getErrorCode());
                 ex=ex.getNextException();
             }
         }
         catch(Exception ex){
             ex.printStackTrace();
         }
         finally{
             try{
                 if(statement !=null){  statement.close();   }
                 if(connection !=null){   statement.close();  }
             }
             
            catch(SQLException ex){
             System.out.println("\nERROR:---- SQLException ----\n");
             while(ex!=null){
                 System.out.println("Message: "+ex.getMessage());
                 System.out.println("SQLState: "+ex.getSQLState());
                 System.out.println("ErrorCode: "+ex.getErrorCode());
                 ex=ex.getNextException();
             }
            } 
        
         }
        }
        public void closeStmt()
    {
        try
        {
            statement.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
    }
    public void closeConn()
    {
        try
        {
            connection.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
    }    
    }
    这是我写的一个连接SQL SERVER2000数据库的JAVABEAN,你把驱动改一下就OK了
    包括数据的基本操作
      

  7.   

    driver=org.gjt.mm.mysql.Driver
    url=jdbc:mysql://localhost/database?useUnicode=true;characterEncoding=gbk
      

  8.   

    private static DataSource ds;
    private static boolean nFirstTime=true;
    private Connection conn;
    try
        {
         Context initCtx = new javax.naming.InitialContext();
              ds =(DataSource)initCtx.lookup(HttpParams.getString(Constants.DATASOURCE));          
        }       
        catch (NamingException e)
        {
         log.error(e.getMessage());
        }  try
    {
          conn=ds.getConnection();
    }
        catch(Exception exp )
        {
         log.error(exp.getMessage());
        }public  ResultSet executeQuery(String sql)
     {
    Statement stmt;
    ResultSet rst;
        rst = null;     
        try
        {
          stmt=conn.createStatement();
          rst = stmt.executeQuery(sql);
        }
        catch(SQLException ex)
        {
         log.error("Query error:"+sql);
        }
        return rst;
     }public  void executeUpdate(String sql) throws SQLException
    {
    Statement stmt;
    ResultSet rst;
        try
        {    
          stmt=conn.createStatement();       
          stmt.executeUpdate(sql);
          stmt.close();       
        }
        catch(SQLException ex)
        {
           log.error("Update error:"+sql);
           throw ex;
        }
    }