请看http://expert.csdn.net/Expert/topic/1689/1689652.xml?temp=.4970056
搞定问题200分都给。
你用的是jdbcodbc桥,要进行设置odbc的数据源的,到管理工具-数据源中设置一下就可以了
按转楼上的设置完dsn后
这样用
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection =DriverManager.getConnection ("jdbc:odbc:dsnname");
try{
//Load JDBC driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
/*这里的数据库的url一定要写正确,这是关键,其中DBQ可以绝对路径,也可以是相对路径,为了体现数据存储路径的/独立性,你可以将数据库copy到不同的位试一下*/
String dbUrl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=access\\test.mdb";
Connection con = DriverManager.getConnection(dbUrl,"","");
Statement state = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
你用什么数据库,如果是SQL-SERVER的话,装一个驱动程序就行了,用不着那么麻烦了
把rt.jar加到环境变量里面
1:jdk开发中系统环境变量设置:
方法如下:
Win2000中:
右键我的电脑--》属性--》高级--》环境环境变量
classpath=.;jdk安装目\lib
path=jdk安装目录\bin
注意:一定不可忽略“.”。
Win98中:
修改autocexe.bat 就是修改自动批处理文件。
添加:
set classpath=.;jdk安装目\lib
set path=jdk安装目录\bin;%path%
2:
不带包的编译,相当简单:
javac 类名.java
java 类名
关于带包的编译问题:
如果你的类是带包的,应该用如下方法编译:
javac -d 包的父目录 类名.java
java 包名.类名
3:Tomcat服务器配置:
1):设置好系统环境变量。
2):JAVA_HOME=G:\JBuilder6\jdk1.3.1
G:\JBuilder6\jdk1.3.1为jdk安装目录
3):TOMCAT_HOME=tomcat安装目录
Servlet基础例程 - HelloServlet
*/
import java.io.*;
import java.text.*; //MessageFormat
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloServlet extends HttpServlet{
//页面标题
protected static final String strTitle = "Servlet基础例程 - HelloServlet";
//页眉
protected static final String strHeader =
"<html>"+
"<head>"+
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">"+
"<title>{0}</title>"+
"</head>"+
"<body>";
//页脚
protected static final String strFooter =
"</body>"+
"</html>";
//表单
protected static final String strForm =
"<form action=\"{0}\" method=\"post\">"+
"您尊姓大名:<input type=\"text\" name=\"name\">"+
"<input type=\"submit\" name=\"submit\" value=\"提交\">"+
"</form>";
protected static final String strHello =
"您好,{0},欢迎来到Servlet/JSP世界!";
//出错信息
protected static final String strError =
"<h2><font color=\"#ff0000\">{0}</font></h2>";
protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
process(req,resp);
}
protected void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
process(req,resp);
}
protected void process(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
try{
String submit = req.getParameter("submit");
if(submit==null)
printForm(req,resp);
else
printHello(req,resp);
}
catch(Exception e){
printError(e.toString(),req,resp);
}
}
protected void printForm(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
//在使用PrintWriter前得先设置Content Type
resp.setContentType("text/html;charset=gb2312");
PrintWriter out = resp.getWriter();
//输出页眉
out.print(MessageFormat.format(strHeader,new Object[]{strTitle+" - 请输入尊姓大名"}));
//输出表单
out.print(MessageFormat.format(strForm,new Object[]{req.getContextPath()+req.getServletPath()}));
//输出页脚
out.print(strFooter);
out.flush();
}
protected void printHello(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
//获取用户输入的数据
String name = req.getParameter("name");
if(name==null)
name = "无名氏";
else
//对用户输入的数据作必要的字符编码转换
name = new String(name.getBytes("iso-8859-1"));
//在使用PrintWriter前得先设置Content Type
resp.setContentType("text/html;charset=gb2312");
PrintWriter out = resp.getWriter();
//输出页眉
out.print(MessageFormat.format(strHeader,new Object[]{strTitle+" - 欢迎您"}));
//输出欢迎信息
out.print(MessageFormat.format(strHello,new Object[]{name}));
//输出页脚
out.print(strFooter);
out.flush();
}
protected void printError(String error, HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
//在使用PrintWriter前得先设置Content Type
resp.setContentType("text/html;charset=gb2312");
PrintWriter out = resp.getWriter();
//输出页眉
out.print(MessageFormat.format(strHeader,new Object[]{strTitle+" - 出错信息"}));
//输出出错信息
out.print(MessageFormat.format(strError,new Object[]{error}));
//输出页脚
out.print(strFooter);
out.flush();
}
是不是没有驱动程序呀