Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jdbc odbc problems

Status
Not open for further replies.

poporogue

Programmer
Dec 20, 2002
16
HK
i've already set the odbc bridge
i don't know where is the mistake...

Unable to connect
java.sql.SQLException: [Microsoft][ODBC ???????] ????????????????????
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3028)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:126)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:256)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:361)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:563)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:535)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:638)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
at java.lang.Thread.run(Thread.java:536)
Jan 24, 2003 10:53:32 AM org.apache.jk.server.JkCoyoteHandler action
INFO: RESET
 
oh..i found what problem that i've got..
it seems to that can't connect to the database
but i've already set the odbc driver, the path is correct and the the dns is correct too...
i'm using nt4.0 with iis and tomcat 4
 
Here's how I connect if that can help you :
Code:
package lgt.jdbc.dbaccess;

import java.io.PrintStream;
import java.sql.*;

// Referenced classes of package lgt.jdbc.dbaccess:
//      DataBaseException

public final class JDBCConnection
{

  public static ResultSet openResultset(String requete)
    throws DataBaseException
  {
    if(requete.toUpperCase().trim().indexOf("SELECT") != 0)
      throw new DataBaseException("La methode openResultset est reservee aux requetes de selection ('SELECT')");
    try
    {
      makeJDBCConnection();
      stmt = getConnection().createStatement();
      rs = stmt.executeQuery(requete);
      return rs;
    }
    catch(SQLException e)
    {
      throw new DataBaseException(e.getErrorCode() + " " + e.getSQLState() + " : " + e.getMessage());
    }
  }

  public static void closeResultset()
    throws DataBaseException
  {
    try
    {
      rs.close();
      stmt.close();
    }
    catch(SQLException e)
    {
      throw new DataBaseException(e.getErrorCode() + " " + e.getSQLState() + " : " + e.getMessage());
    }
  }

  public static int execute(String requete)
    throws DataBaseException
  {
    String test = requete.toUpperCase().trim();
    if(test.indexOf("INSERT") != 0 && test.indexOf("UPDATE") != 0 && test.indexOf("DELETE") != 0)
      throw new DataBaseException("La methode execute est reservee aux requetes action ('INSERT', 'UPDATE', 'DELETE')");
    try
    {
      makeJDBCConnection();
      Statement stmt1 = getConnection().createStatement();
      int nbRows = stmt1.executeUpdate(requete);
      return nbRows;
    }
    catch(SQLException e)
    {
      throw new DataBaseException(e.getErrorCode() + " " + e.getSQLState() + " : " + e.getMessage());
    }
  }

  private JDBCConnection()
  {
    cnx = null;
    try
    {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      cnx = DriverManager.getConnection("JDBC:ODBC:Tech", "sa", "");
    }
    catch(ClassNotFoundException e)
    {
      System.err.println(e.getClass().getName() + " : Driver non trouv\351.");
    }
    catch(SQLException e)
    {
      System.err.println(e.getClass().getName() + " : Erreur de connexion \340 la base de donn\351es.");
    }
  }

  public static Connection getConnection()
  {
    try
    {
      if(cnx.isClosed())
        cnx = DriverManager.getConnection("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(SQLException e)
    {
      cnx = null;
      System.err.println(e.getClass().getName() + " : Erreur de connexion \340 la base de donn\351es.");
    }
    return cnx;
  }

  public static JDBCConnection makeJDBCConnection()
  {
    if(jdbcCnx == null)
    jdbcCnx = new JDBCConnection();
    return jdbcCnx;
  }

  private static JDBCConnection jdbcCnx = null;
  private static Connection cnx;
  private static Statement stmt;
  private static ResultSet rs;

}

Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top