不知道这个数据连接发生什么错误,请高手指点
package com.zgm.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import
java.sql.SQLException;
import java.sql.Statement;
public final class JdbcUtils {
private final static String url = "jdbc:oracle:thin:@localhost:1521:XE";
private final static String user = "scott";
private final static String password = "tiger";
private void jdbcUtils() {
}
static {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (
ClassNotFoundException e) {
throw new
ExceptionInInitializerError(e);
}
}
public static Connection getConnection() throws
SQLException {
return DriverManager.getConnection(url, user, password);
}
public static void free(ResultSet rs, Statement st, Connection conn) {
try {
if (rs != null)
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (st != null)
st.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (conn != null)
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
package com.zgm.jdbc;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DB {
public static void main(String[] args) throws Exception {
read();
}
static void read() throws SQLException {
Connection conn=null;
Statement st=null;
ResultSet rs=null;
try{
conn=JdbcUtils.getConnection();
st=conn.createStatement();
rs=st.executeQuery("select * from ROOT");
while(rs.next()){
System.out.println(rs.getObject(1)+"\t"+rs.getObject(2)+"\t"+rs.getObject(3));
}
}finally{
JdbcUtils.free(rs, st, conn);
}
}
}
Exception in thread "main"
java.lang.NoClassDefFoundError: Could not initialize class com.zgm.jdbc.JdbcUtils
at com.zgm.jdbc.DB.read(DB.java:29)
at com.zgm.jdbc.DB.main(DB.java:13)
------解决方案--------------------
无法找到com.zgm.jdbc.JdbcUtils这个类的定义。
main函数发生错误
------解决方案--------------------在那个JdbcUtils旁边Alt+/