标题:用javabean连接sql 2000连接不上(已解决,配置有问题)
只看楼主
z108979979
Rank: 1
等 级:新手上路
威 望:1
帖 子:252
专家分:0
注 册:2006-6-19
得分:0 
明白了
没看清楚

2006-09-15 09:25
pchelp2008
Rank: 1
等 级:新手上路
威 望:1
帖 子:177
专家分:0
注 册:2006-8-2
得分:0 
我还没明白,怎么连不上,连了两天还不行,郁闷!

[此贴子已经被作者于2006-9-15 12:14:59编辑过]



天才=勤奋+汗水ggggggggggggggggg
2006-09-15 12:14
无理取闹
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:53
帖 子:4264
专家分:0
注 册:2006-7-26
得分:0 
我说的方法你试了么?用main测试一下

win32汇编
病毒 加密
目前兴趣所在
2006-09-15 15:41
球球
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:1146
专家分:265
注 册:2005-11-28
得分:0 
以下是引用pchelp2008在2006-9-14 11:25:13的发言:


我用了:ResultSet rs=conn.executeQuery(sql);这句
应该是ResultSet rs=st.executeQuery(sql);
出现了这个:,没定义呢:

你定义的是stmt,用st当然没定义了.


好累
2006-09-15 22:25
球球
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:1146
专家分:265
注 册:2005-11-28
得分:0 

//firm.java
package firm;

import java.sql.*;
import java.io.*;
import java.util.*;

public class firm
{
public Connection conn = null;
public Statement stmt = null;
public ResultSet rs = null;
// private static String propFileName = "C:/connDB.properties";
// private static Properties prop = new Properties();
private static String dbClassName ="sun.jdbc.odbc.JdbcOdbcDriver";
private static String dbUrl ="jdbc:odbc:driver=sql server;server=(local);database=GuestBook";
private static String dbUser = "sa";
private static String dbPwd = "";

public static Connection getConnection()
{
Connection conn = null;
try
{
Class.forName(dbClassName).newInstance();
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
}
catch (Exception ee)
{
ee.printStackTrace();
}
if (conn == null)
{
System.err.println(
"警告: DbConnectionManager.getConnection() 获得数据库链接失败.\r\n\r\n链接类型:" +
dbClassName + "\r\n链接位置:" + dbUrl + "\r\n用户/密码" + dbUser + "/" +
dbPwd);
}
return conn;
}

/*
*功能:执行查询语句
*/
public ResultSet executeQuery(String sql)
{
try
{
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
}
catch (SQLException ex)
{
System.err.println(ex.getMessage());
}
return rs;
}

/*
*功能:执行更新操作
*/
public int executeUpdate(String sql)
{
int result = 0;
try
{
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
result = stmt.executeUpdate(sql);
}
catch (SQLException ex)
{
result = 0;
}
try
{
stmt.close();
}
catch (SQLException ex1)
{
}
return result;
}
/*
*功能:关闭数据库的连接
*/
public void close()
{
try
{
if (rs != null)
{
rs.close();
}
}
catch (Exception e)
{
e.printStackTrace(System.err);
}
try
{
if (stmt != null)
{
stmt.close();
}
}
catch (Exception e)
{
e.printStackTrace(System.err);
}
try
{
if (conn != null)
{
conn.close();
}
}
catch (Exception e)
{
e.printStackTrace(System.err);
}
}

}

////////////////////////////////////////////////////
//index.jsp
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.sql.*"%>
<jsp:useBean id="firm" scope="page" class="firm.firm" />
<%
String sql="select * from GuestBook";
ResultSet rs=firm.executeQuery(sql);

String name=null;
if(rs.next()){
name=rs.getString("uname");
}
%>
<html>
<head>
</head>
<body>
<%= name%>
</body>
</html>
//表:
create database GuestBook

create table GuestBook
(
uname varchar(10),
age int
)

insert into GuestBook values('aa',2)

结果为:aa
把驱动和连接改了:
private static String dbClassName ="sun.jdbc.odbc.JdbcOdbcDriver";
private static String dbUrl ="jdbc:odbc:driver=sql server;server=(local);database=GuestBook";
然后你的
<jsp:userBean ...... />
写错了,应该是<jsp:useBean id="firm" scope="page" class="firm.firm" />


好累
2006-09-15 23:47
pchelp2008
Rank: 1
等 级:新手上路
威 望:1
帖 子:177
专家分:0
注 册:2006-8-2
得分:0 

韩峰的main方法,我不知道怎么测,所以...........
我用了25楼的,出现这样的!它说50行有错误;
description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /11.jsp:6

3: <jsp:useBean id="firm" scope="page" class="firm.firm" />
4: <%
5: String sql="select * from Guest_Book";
6: ResultSet rs=firm.executeQuery(sql);
7: out.print(rs);
8: %>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
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

java.lang.NullPointerException
firm.firm.executeQuery(firm.java:50)

org.apache.jsp._11_jsp._jspService(_11_jsp.java:61)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
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)

[此贴子已经被作者于2006-9-18 12:54:42编辑过]


天才=勤奋+汗水ggggggggggggggggg
2006-09-16 08:16
球球
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:1146
专家分:265
注 册:2005-11-28
得分:0 
我再运行了一遍很正常.
那就把它除掉.....
还有jsp中导入的包java.text.*,java.util.*,HYBTX.sys.data.*,HYBTX.info.*
我不知道这些是干什么用的???
HYBTX.sys.data.*,HYBTX.info.*这又是什么意思?
不相干的包就不要导入了.

好累
2006-09-17 10:55
pchelp2008
Rank: 1
等 级:新手上路
威 望:1
帖 子:177
专家分:0
注 册:2006-8-2
得分:0 

现在好像好了点,但还是有这么一个错误!难道配置有问题!

An error occurred at line: 3 in the jsp file: /11.jsp
Generated servlet error:
ResultSet cannot be resolved to a 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


[此贴子已经被作者于2006-9-18 8:26:13编辑过]


天才=勤奋+汗水ggggggggggggggggg
2006-09-18 08:25
tblovecj
Rank: 1
等 级:新手上路
帖 子:181
专家分:0
注 册:2006-9-20
得分:0 
连接数据库的区别
兄弟,我先问一下你的操作系统是什么,你写的微软的驱动连接,在XP系统上连不起,如果你是用的XP,我建意你有桥连接方式,应该能行的,就是"sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:(此处填写你的数据源名)"

2006-09-20 00:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-89906-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.064441 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved