resin下jdbc怎么用?(100分)

S

sdcx

Unregistered / Unconfirmed
GUEST, unregistred user!
我用的mssql jdbc,我在classpath里设置了,又把3个jar文件copy到resin的Lib下了,
还是不行,提示
500 Servlet Exception
java.lang.NullPointerException
at _test__jsp._jspService(/test.jsp:18)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:497)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:344)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:274)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:536)

源代码:
<%@ page import="java.sql.*" %>
<%@ page import="com.caucho.*" %>
<%! Connection con=null;
ResultSet rs=null;
Statement stmt=null;
String drver="com.microsoft.jdbc.sqlserver.SQLServerDriver";%>
<% try{
Class.forName(drver);
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.100.201:1433;DatabaseName=book");
rs=stmt.executeQuery("select * from dc");
while(rs.next()){ %>
<%=rs.getString("word")%>
<% } }//end try
catch(ClassNotFoundException e){
out.print("class err");
}
catch(SQLException e){
out.print("sql err");
}
rs.close();
stmt.close();
con.close();
%>
 
只要在jdk中设置就好了,将jar考至jre/lib/ext下,就成了。
 
>>com.microsoft.jdbc.sqlserver.SQLServerDriver
对应的路径应该是
com/microsoft/jdbc/sqlserver/SQLServerDriver
你看一下在JAR文件里的压缩包路径是否跟这个一致!
如果不一致则将你的连接字符串改成相应的格式
 
将try结构去掉试一下
 
服了你。
stmt未赋值呀!!!在con中get出Statement...
 
多人接受答案了。
 
顶部