jsp连接Sybase数据库 
testmysql.jsp如下: <%@ page contentType="text/html;charset=gb2312"%> 
<%@ page import="java.sql.*"%> 
<html> 
<body> 
<%Class.forName("com.sybase.jdbc.SybDriver").newInstance(); 
String url =" jdbc:sybase:Tds:localhost:5007/tsdata"; 
//tsdata为你的数据库名 
Properties sysProps = System.getProperties(); 
SysProps.put("user","userid"); 
SysProps.put("password","user_password"); 
Connection conn= DriverManager.getConnection(url, SysProps); 
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
String sql="select * from test"; 
ResultSet rs=stmt.executeQuery(sql); 
while(rs.next()) {%> 
您的第一个字段内容为:<%=rs.getString(1)%> 
您的第二个字段内容为:<%=rs.getString(2)%> 
<%}%> 
<%out.print("数据库操作成功,恭喜你");%> 
<%rs.close(); 
stmt.close(); 
conn.close(); 
%> 
</body> 
</html> 

解决方案 »

  1.   

    看看下面这个帖子http://www.csdn.net/Develop/read_article.asp?id=25942Sybase的URL和Driver Name也在下面
    Class.forName("com.sybase.jdbc.SybDriver").newInstance(); 
    String url =" jdbc:sybase:Tds:localhost:5007/tsdata"; 
      

  2.   

    我晕,人家要得是连接池的配置。
    给个jdbc有什么用啊
      

  3.   

    是啊,怎么给人家一个JDBC.谁有TOMCAT+ORACLE的连接池,也给写出来,让俺学习学习?
      

  4.   

    你不想用TOmcat自带的连接池么?挺好用的呀。下面是代码写的连接池,
    贴出2个java文件代码:
    //================= ConnectionBean.java ===================
    import java.io.Serializable;
    import java.sql.*;
    public class ConnectionBean implements java.io.Serializable
      {
      private Connection connection = null;
      private boolean inuse = false;
      public ConnectionBean()
        { }
      public ConnectionBean(Connection value)
        { if (value!=null) connection = value; }
      public Connection getConnection()
        { return connection; }
      public void setConnection(Connection con)
        { connection = con; }
      public void setInuse(boolean value)
        { inuse = value; }
      public boolean getInuse()
        { return inuse; }
      public boolean inUse()
        { return inuse; }
      public void close()
        {
        try
          { connection.close(); }
        catch (SQLException sqle)
          { System.err.println(sqle.getMessage()); }
        }
      }
      

  5.   

    //==================== PoolBean.java ======================
    import java.io.Serializable;
    import java.sql.*;
    import java.util.*;
    public class PoolBean implements java.io.Serializable
      {
      private String driver = null;
      private String url = null;
      private int size = 0;
      private String username = new String("");
      private String password = new String("");
      private Vector pool = null;
      public PoolBean() { }
      public void setDriver(String value)
        { if (value!=null) driver=value; }
      public String getDriver()
        { return driver; }
      public void setURL(String value )
        { if (value!=null) url=value; }
      public String getURL()
        { return url; }
      public void setSize(int value)
        { if (value>1) size=value; }
      public int getSize()
        { return size; }
      public void setUsername(String value)
        { if (value!=null) username=value; }
      public String getUserName()
        { return username; }
      public void setPassword(String value)
        { if (value!=null) password=value; }
      public String getPassword()
        { return password; }
      private Connection createConnection() throws Exception
        {
        Connection con = null;
        con = DriverManager.getConnection(url,username,password);
        return con;
        }
      public synchronized void initializePool() throws Exception
        {
        if (driver==null)
          throw new Exception("No Driver Name Specified!");
        if (url==null)
          throw new Exception("No URL Specified!");
        if (size<1)
          throw new Exception("Pool size is less than 1!");
        try
          {
          Class.forName(driver);
          for (int x=0; x<size; x++)
            {
            Connection con = createConnection();
            if (con!=null)
              {
              ConnectionBean pcon = new ConnectionBean(con);
              addConnection(pcon);
              }
            }
          }
        catch (Exception e)
          {
          System.err.println(e.getMessage());
          throw new Exception(e.getMessage());
          }
        }
      private void addConnection(ConnectionBean value)
        {
        if (pool==null) pool=new Vector(size);
        pool.addElement(value);
        }
      public synchronized void releaseConnection(Connection con)
        {
        for (int x=0; x<pool.size(); x++)
          {
          ConnectionBean pcon =
            (ConnectionBean)pool.elementAt(x);
          if (pcon.getConnection()==con)
            {
            System.err.println("Releasing Connection " + x);
            pcon.setInUse(false);
            break;
            }
          }
        }
      public synchronized Connection getConnection()
      throws Exception
        {
        ConnectionBean pcon = null;
        for (int x=0; x<pool.size(); x++)
          {
          pcon = (ConnectionBean)pool.elementAt(x);
          if (pcon.inUse()==false)
            {
            pcon.setInUse(true);
            return pcon.getConnection();
            }
          }
        try
          {
          Connection con = createConnection();
          pcon = new ConnectionBean(con);
          pcon.setInUse(true);
          pool.addElement(pcon);
          }
        catch (Exception e)
          {
          System.err.println(e.getMessage());
          throw new Exception(e.getMessage());
          }
        return pcon.getConnection();
        }
      public synchronized void emptyPool()
        {
        for (int x=0; x<pool.size(); x++)
          {
          System.err.println("Closing JDBC Connection " + x);
          ConnectionBean pcon =
            (ConnectionBean)pool.elementAt(x);
          if (pcon.inUse()==false)
            pcon.close();
          else
            {
            try
              {
              java.lang.Thread.sleep(30000);
              pcon.close();
              }
            catch (InterruptedException ie)
              {
              System.err.println(ie.getMessage());
              }
            }
          }
        }
      }
      

  6.   

    我觉得还是Tomcat自带的连接池好用一点。
      

  7.   

    CoolAbu(阿卜-Never Stop(★★★★)) 
    这个是自己写的吧,,,我很想在server.xml 和web.xml 里配置的,公司这样要求我做,,,,我配了很就都不行,,另外:nyliuhaiyang(lhy) 我这里有一个是适合你的:http://www.zdnet.com.cn/developer/code/story/0,2000081534,39134180,00.htm我参考的是上面那个和http://www.csdn.net/Develop/article/25/25942.shtm但都不行,我的数据库是sydase的,,,,各位那个会的帮忙一下,很急用