我想把JSp连接access数据库的代码改写成连接SQL2005数据库的代码,需要改哪里
这是javabean程序,需要改哪里?我改
connect = DriverManager.getConnection(sConnStr,"sa","123456");还是连不上啊
package vote;
import java.sql.*;
public class VoteConn {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:vote";
Connection connect = null;
ResultSet rs = null;
public VoteConn() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println( e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
try {
connect = DriverManager.getConnection(sConnStr);
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql) {
int result = 0;
try {
connect = DriverManager.getConnection(sConnStr);
Statement stmt = connect.createStatement();
result = stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return result;
}
}
错误信息:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:498)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:427)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
答案:空指针错误,有没有可能是SQL出错?
其他:String sDBDriver ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
这个才是SQL的驱动,至于sConnStr里存放的是什么就不明白了,vote是数据库名吗?把odbc改成sqlserver试一下。 分值好诱人啊。。。
上一个:在线投票系统 用jsp做的 希望有详细的步骤过程、源代码、图片 万分感谢啦
下一个:jsp javascript代码无法执行 提示传进去的参数为定义