Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 windows2003安装jdbc连接sql server2000+sp3的问题急!!!
sykt





发贴: 2
积分: 0
于 2006-03-24 12:55 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我系统windows2003+tomcat+jdk这些运行都没有问题作JSP页面什么的。装上sql server 2000打sp3补丁下载jdbc for sql server 2000+sp3补丁装上后,CLASSPATH也配了。。用代码测试
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="err.jsp" %>
<%@ page import="java.util.*"%>
<%
public class Connect{
private java.sql.Connection con = null;
private final String url = "jdbc:microsoft:sqlserver://";
private final String serverName= "localhost";
private final String portNumber = "1433";
private final String databaseName= "university";
private final String userName = "admin";
private final String password = "*****";
// Informs the driver to use server a side-cursor,
// which permits more than one active statement
// on a connection.
private final String selectMethod = "cursor";

// Constructor
public Connect(){}

private String getConnectionUrl(){
return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
}

private java.sql.Connection getConnection(){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
if(con!=null) System.out.println("Connection Successful!");
}catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
return con;
}

/*
Display the driver properties, database details
*/

public void displayDbProperties(){
java.sql.DatabaseMetaData dm = null;
java.sql.ResultSet rs = null;
try{
con= this.getConnection();
if(con!=null){
dm = con.getMetaData();
System.out.println("Driver Information");
System.out.println("\tDriver Name: "+ dm.getDriverName());
System.out.println("\tDriver Version: "+ dm.getDriverVersion ());
System.out.println("\nDatabase Information ");
System.out.println("\tDatabase Name: "+ dm.getDatabaseProductName());
System.out.println("\tDatabase Version: "+ dm.getDatabaseProductVersion());
System.out.println("Avalilable Catalogs ");
rs = dm.getCatalogs();
while(rs.next()){
System.out.println("\tcatalog: "+ rs.getString(1));
}
rs.close();
rs = null;
closeConnection();
}else System.out.println("Error: No active Connection");
}catch(Exception e){
e.printStackTrace();
}
dm=null;
}

private void closeConnection(){
try{
if(con!=null)
con.close();
con=null;
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception
{
Connect myDbTest = new Connect();
myDbTest.displayDbProperties();
}
}
%>
就提示这些东东:
type Exception report

message

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: 3 in the jsp file: /testsql.jsp
Generated servlet error:
Illegal modifier for the local class Connect; only one of abstract or final is permitted

An error occurred at line: 3 in the jsp file: /testsql.jsp
Generated servlet error:
The method main cannot be declared static; static methods can only be declared in a static or top level type

  org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 3 in the jsp file: /testsql.jsp
Generated servlet error:
Illegal modifier for the local class Connect; only one of abstract or final is permitted

An error occurred at line: 3 in the jsp file: /testsql.jsp
Generated servlet error:
The method main cannot be declared static; static methods can only be declared in a static or top level type

  org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
  org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
  org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:413)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
  org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.16 logs.

--------------------------------------------------------------------------------
代码我都检查多少回了没什么问题,弄了两天了也不知道是哪的问题是数据库没联上还是本身代码的问题。请高手指教谢谢了



作者 Re:windows2003安装jdbc连接sql server2000+sp3的问题急!!! [Re:sykt]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-03-24 21:09 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
> Illegal modifier for the local class Connect; only one of abstract or final is permitted
> The method main cannot be declared static; static methods can only be declared in a static or top level type
数据库没联上???
Clearly 本身代码的问题!

Why would you include a class in a JSP? Question



作者 Re:windows2003安装jdbc连接sql server2000+sp3的问题急!!! [Re:why]
sykt





发贴: 2
积分: 0
于 2006-03-27 08:16 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
谢谢!问题已解决。本身代码写的有问题



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923