日期:2014-05-20  浏览次数:20630 次

jsp连接odbc问题
<%@ page contentType="text/html;charset=GB2312" language="java" %>
<%@ page import="java.sql.*"%>
<html>
<head><title>JDBC-ODBC连接 SQL Server</title></head>
<%
  Connection conn=null;
  try
  {
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  String strConn="JDBC:odbc:shopData";
  String strUser="sa";
  String strPassword="123456";
  conn=DriverManager.getConnection(strConn,strUser,strPassword);
  out.println("<h2>JDBC-ODBC连接数据库成功!<h2>");
  }
  catch(ClassNotFoundException e)
  {
  out.println(e.getMessage());
  }
  catch(SQLException e)
  {
  out.println(e.getMessage());
  }
  finally
  {
  try 
  {
  if(conn!=null)
  conn.close();
  }
  catch(Exception e){}
  }
%>
</html>

结果出现:[Microsoft][ODBC 驱动程序管理器] 在指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配

------解决方案--------------------
strConn的格式有没有错
------解决方案--------------------
系统里面配置ODBC了吗。控制面版——管理——数据源


这种代码为什么写在页面里面。浪费青春

------解决方案--------------------
你需要在本机电脑上面配置ODBC数据源。楼上正解。详情。去百度一下。有图有JB。

还在你的页面写java代码。还在用odbc。