当前位置: 技术问答>java相关
关于JDBC的很菜的问题,送分了
来源: 互联网 发布时间:2015-02-22
本文导语: 我用以下例子: import java.sql.*; public class faq { String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; String sConnStr = "jdbc:odbc:kelong"; Connection conn = null; ResultSet rs = null; public faq() { try { Class.forName(sDBDriver); } catch(java.lang.Clas...
我用以下例子:
import java.sql.*;
public class faq {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:kelong";
Connection conn = null;
ResultSet rs = null;
public faq() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("faq(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
报错为:Exception in thread "main" java.lang.NoClassDefFoundError:faq
怎么解决?
import java.sql.*;
public class faq {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:kelong";
Connection conn = null;
ResultSet rs = null;
public faq() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("faq(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
报错为:Exception in thread "main" java.lang.NoClassDefFoundError:faq
怎么解决?
|
没有设环境变量,把该类所在的目录设到环境变量里,试试看
|
你的main方法在faq中吗,如果不是的话,你就应该在classpath中设置你的faq或者在path中设置上你的faq所在的目录。
|
http://www.csdn.net/expert/TopicView.asp?id=85391