servlet连接ACCESS数据库
在index.jap页面里有一个按钮,用来提交页面,点击后运行a这个servlet测试数据库连接是否成功
这个是index.jsp
HTML code
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<body>
<form action="servlet/a" method="post">
<input type="submit" value="提交"/>
</form>
</body>
</html>
这是a这个servlet
Java code
package chapter3;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class a extends HttpServlet {
//用于处理GET、POST等HTTP请求的方法
protected void service(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:myaccess", "oyms", "oyms");
System.out.println("数据库链接成功...");
}catch (Exception e)
{
e.printStackTrace();
}
}
}
运行后出错:
java.sql.SQLException: No data found
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at chapter3.a.service(a.java:15)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Unknown Source)
不知连接access的时候连接字符串怎么写?数据库文件该放到哪里?
------解决方案--------------------
http://topic.csdn.net/u/20091213/22/95E1DF4C-2A21-469D-AC77-5114717EA836.html
楼主可以参考看看
------解决方案--------------------
放点数据进去,试试