jsp怎么连接sql2005数据库啊 ,好纠结啊,能有人在线指导一下吗?
按照网上的代码和书上的代码,都连接不成功啊 ,都不知道哪出问题了。JSP数据库sql2005
按照网上的代码和书上的代码,都连接不成功啊 ,都不知道哪出问题了。JSP数据库sql2005
解决方案 »
- struts 2中action取页面request对象中的对象能取出来么?
- sql server2000 sp4的问题
- LogFactory.getLog(),Logger.getLogger()这两种记录日志的方法有撒区别啊?谢拉!
- 可以同时装sql server2000和mysql5.0.18吗?
- 使用JAVABEAN时,在TOMCAT服务器里怎样配置,,
- 谁帮我讲讲网站的邮件系统是怎么实现的??
- 工资调查,请同行们报出你们的工资!我不提成(:呵呵!
- 请问一个字符串比较的问题!
- mysql 模糊查询的两条sql语句查询出来的结果不一样
- 关于Java自定义注解的疑问
- 过滤器用户登录
- 怎么获取执行过的所有sql语句
jdbc连接数据库总的不就那么两行代码吗。
加载驱动,打开连接
//------------文件名:connection.jsp----------
<% @ page language="java" import="java.util.*" %>
<% @ page import = "java.sql.*" %>
<html>
<head>
<title>JSP连接SQL Server数据库示例</title>
</head>
<body>
<%
Connection conn= null;
//加载数据库驱动
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//连接数据库URL
String url ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
//数据库用户名
String user = "sa";
//数据库密码
String password ="13518035521xxss";
//根据数据库参数取得一个数据库连接
conn = DriverManager.getConnection(url,user,password);
out.print("取得一个数据库连接: \n");
out.print(conn.toString());
%>
</body>
</html>
错误显示:type Exception reportmessage Unable to compile class for JSP: description The server encountered an internal error that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 2 in the jsp file: /work.jsp
Syntax error on token "language", VariableDeclaratorId expected after this token
1: //------------文件名:connection.jsp----------
2: <% @ page language="java" import="java.util.*" %>
3: <% @ page import = "java.sql.*" %>
4: <html>
5: <head>
An error occurred at line: 2 in the jsp file: /work.jsp
language cannot be resolved to a type
1: //------------文件名:connection.jsp----------
2: <% @ page language="java" import="java.util.*" %>
3: <% @ page import = "java.sql.*" %>
4: <html>
5: <head>
An error occurred at line: 2 in the jsp file: /work.jsp
The left-hand side of an assignment must be a variable
1: //------------文件名:connection.jsp----------
2: <% @ page language="java" import="java.util.*" %>
3: <% @ page import = "java.sql.*" %>
4: <html>
5: <head>
An error occurred at line: 2 in the jsp file: /work.jsp
Syntax error on token "import", delete this token
1: //------------文件名:connection.jsp----------
2: <% @ page language="java" import="java.util.*" %>
3: <% @ page import = "java.sql.*" %>
4: <html>
5: <head>
An error occurred at line: 2 in the jsp file: /work.jsp
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
1: //------------文件名:connection.jsp----------
2: <% @ page language="java" import="java.util.*" %>
3: <% @ page import = "java.sql.*" %>
4: <html>
5: <head>
An error occurred at line: 3 in the jsp file: /work.jsp
Syntax error, insert "enum Identifier" to complete EnumHeaderName
1: //------------文件名:connection.jsp----------
2: <% @ page language="java" import="java.util.*" %>
3: <% @ page import = "java.sql.*" %>
4: <html>
5: <head>
6: <title>JSP连接SQL Server数据库示例</title>
An error occurred at line: 3 in the jsp file: /work.jsp
Syntax error, insert "EnumBody" to complete BlockStatement
1: //------------文件名:connection.jsp----------
2: <% @ page language="java" import="java.util.*" %>
3: <% @ page import = "java.sql.*" %>
4: <html>
5: <head>
6: <title>JSP连接SQL Server数据库示例</title>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
把最有那个新实便给Delete;
还有;
Connection conn = null; 不能等于null ; 不然这个一直都是空, 如果报错的话;
你可以;Connection conn = DriverManager.getConnection(url,user,password);
SQL Server 2005:com.microsoft.sqlserver.jdbc.SQLServerDriver
这说的还不够详细吗,把connection.jsp上面的page标签去掉试试。
这说的还不够详细吗,把connection.jsp上面的page标签去掉试试。试过了,不行也
这个目录是在哪的呀,我不太清楚这点,是tomcat的?