当前位置: 技术问答>java相关
Resin 2.1.6 500 Servlet Exception,用jdbc连接sql-server数据库出毛病?很奇怪!谢谢大家!我有急用!在线等待!
来源: 互联网 发布时间:2017-03-25
本文导语: Resin 2.1.6 500 Servlet Exception,用jdbc连接sql-server数据库出毛病? 提示: D:Apache2htdocsWEB-INFclassesorderorder.java:11: Exception java.lang.InstantiationException must be caught, or it must be declared in the throws clause of this constructor. Class.f...
Resin 2.1.6 500 Servlet Exception,用jdbc连接sql-server数据库出毛病?
提示:
D:Apache2htdocsWEB-INFclassesorderorder.java:11: Exception java.lang.InstantiationException
must be caught, or it must be declared in the throws clause of this constructor.
Class.forName(sDBDriver).newInstance();
不过查询记录还可以用,我用的javabean封装的数据库连接:
package order;
import java.sql.*;
public class order {
//JDBC连接
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String sConnStr = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=order";
Connection conn = null;
ResultSet rs = null;
public order() {
try {
Class.forName(sDBDriver).newInstance();
}
catch(java.lang.ClassNotFoundException e) {
System.err.println(e.getMessage());
}
}
//定义public型函数
public ResultSet executeQuery(String sql) {
rs = null;
String user="sa";
String password="sa";
try {
conn = DriverManager.getConnection(sConnStr,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
用javac无法编译,提示
order.java:11.unreported exception java.lang.InstantiationException;must
be caught or declared to be thrown
class.forName(sDBDriver).newInstance();
谢谢大家!我有急用!在线等待!
提示:
D:Apache2htdocsWEB-INFclassesorderorder.java:11: Exception java.lang.InstantiationException
must be caught, or it must be declared in the throws clause of this constructor.
Class.forName(sDBDriver).newInstance();
不过查询记录还可以用,我用的javabean封装的数据库连接:
package order;
import java.sql.*;
public class order {
//JDBC连接
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String sConnStr = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=order";
Connection conn = null;
ResultSet rs = null;
public order() {
try {
Class.forName(sDBDriver).newInstance();
}
catch(java.lang.ClassNotFoundException e) {
System.err.println(e.getMessage());
}
}
//定义public型函数
public ResultSet executeQuery(String sql) {
rs = null;
String user="sa";
String password="sa";
try {
conn = DriverManager.getConnection(sConnStr,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
用javac无法编译,提示
order.java:11.unreported exception java.lang.InstantiationException;must
be caught or declared to be thrown
class.forName(sDBDriver).newInstance();
谢谢大家!我有急用!在线等待!
|
try{
class.forName(sDBDriver).newInstance();
}catch(Exception e){
e.printStackTrace();
}
class.forName(sDBDriver).newInstance();
}catch(Exception e){
e.printStackTrace();
}
|
因为你没有捕获InstantiationException这个异常
|
JSP-JDBC网页
连接Mysql数据库!
试试,如不好使,classpath问题或JDBC驱动问题。驱动我可以给你发。你的信箱。BEAN路径设了吗?
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。