java监控jdbc connect,Java开发网 - jdbc的问题(Connection 不能实例化,不能建立连接)...

Posted by:sumind206xy

Posted on:2006-08-24 10:46

最近做了个小项目,在本pc上测试一切正常,于是就传到服务器上,谁知道一上服务器,我那个连接数据库的javabean就抛出空指针异常,最后发现是 stmt(stetament )的问题,没办法,只好写了个测试页面试试连接,结果一执行到Connection con = DriverManager.getConnection(url, username,password);就抛出异常,各位帮忙看下是什么原因?是什么情况才会导致这个原因?

testcon.jsp:

String basePath = request.getScheme() + "://" + request.getServerName() + ":" +request.getServerPort()+ path + "/";

%>

My JSP 'MyJsp.jsp' starting page

Statement stmt;

ResultSet rst;

String classforname = "com.microsoft.jdbc.sqlserver.SQLServerDriver";

String username = "sa";

String password = "sa";

String url = "jdbc:microsoft:sqlserver://192.168.1.27:1433;DatabaseName=project_news";

%>

Class.forName(classforname).newInstance();

out.print("111");

Connection con = DriverManager.getConnection(url, username,password);

out.print("222");

stmt = con.createStatement();

out.print("333");

rst = stmt.executeQuery("select * from project_baseinfo");

out.print("444");

} catch (Exception e) {

e.printStackTrace();

out.print("555");

}

%>

while (rst.next()) {

out.print("ok");

}

}catch (Exception e) {

out.print("666");

}

%>

This is my JSP page.

打印结果:111 555 666 this is my JSP page

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值