日期:2014-05-17  浏览次数:20870 次

急急急`````jdbc连接到数据库的问题
我只是吧jdbc解压到了一个新建的文件夹后,管理工具-数据源(odbc)-添加-SQL server-名称,描述,服务器.-默认到完成.
然后编写了<%@page language="java" contentType="text/html;charset=gb2312" page-Encoding="gb2312" %>
<%@page import="java.util.*" %>
<%@page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>创建数据库</title>
</head>
<body><font size=2>
<%
Connection conn=null;
Statement stmt=null;
String sql=null;
ResultSet rs=null;
int ret;
try{
Class.forName("com.SQL server.jdbc.Driver");
String strCon="jdbc:microsoft:sqlserver://localhost:1433";
conn=DriverManager.getConnection(strCon,"root","root");
stmt=conn.createStatement();
sql="create database LHX ";
ret=stmt.executeUpdate(sql);
sql="use LHX";
ret=stmt.executeUpdate(sql);
sql="create table customers("+
"ID int(6) unsigned NOT NULL auto_increment,"+
"Name varchar(20) default NUll,"+
"addTime timestamp NULL default NULL,"+
"Tel varchar(15) default NULL,"+
"Email varchar(20) default NULL,"+
"PRIMARY KEY (ID)"+
")";
ret=stmt.executeUpdate(sql);
}
catch(ClassNotFoundException e){
e.printStackTrace();
out.println("<h1>无法找到数据库驱动</h1>");
}
catch(SQLException e1){
e1.printStackTrace();
out.println("<h1>数据库操纵失败</h1>");
}
out.println("<h1>新建数据库LHX成功</h1>");
DatabaseMetaData meta=conn.getMetaData();
out.println("<br>");
out.println("连接字:"+meta.getURL());
out.println("<br>");
out.println("数据库产品:"+meta.getDatabaseProductName());
out.println("<br>");
out.println("数据库版本:"+meta.getDatabaseProductVersion());
out.println("<br>");
out.println("驱动程序:"+meta.getDriverName());
out.println("<br>");
out.println("驱动程序版本:"+meta.getDriverVersion());

stmt.close();
conn.close();
%>
</font>
</body>
</html>
出现了这个,是什么原因HTTP Status 500 - 

--------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: /Test5_1.jsp(1,1) Page directive has invalid attribute: page-Encoding
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:83)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:402)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:236)
org.apache.jasper.compiler.JspUtil.checkAttributes(JspUtil.java:348)
org.apache.jasper.compiler.Validator$DirectiveVisitor.visit(Validator.java:144)
org.apache.jasper.compiler.Node$PageDirective.accept(Node.java:578)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2180)
org.