Olá p pessoal…
Estou ainda com esse erro que não consigo entender… alguém sabe o que pode ser?? O que significa? O que tenho q fazer?
[color=“blue”]
"java.lang.NoClassDefFoundError: javax/sql/DataSource
Exception in thread “main” "[/color]
Olá p pessoal…
Estou ainda com esse erro que não consigo entender… alguém sabe o que pode ser?? O que significa? O que tenho q fazer?
[color=“blue”]
"java.lang.NoClassDefFoundError: javax/sql/DataSource
Exception in thread “main” "[/color]
tem como por seu código ae…?
esse erro é pq ele naum está localizando o pacote javax.sql.DataSource…
Aqui está a classe que contém o main:
[code]public class Teste {
private Dbcp p = new Dbcp();
public static void main(String[ ] args) {
Teste t = new Teste();
System.out.println(t.p);
}
}[/code]
a classe Dbcp, que está no mesmo pacote é:
[code]import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
public class Dbcp {
private static Dbcp instance = null;
private DataSource ds;
private Connection con;
private String driver;
private String url;
private String login;
private String password;
private int maxConnections;
private long maxWait;
public Dbcp() {
Properties props = new Properties();
try {
InputStream fis = this.getClass().getClassLoader().getResourceAsStream("db.properties");
props.load(fis);
fis.close();
}
catch(FileNotFoundException f) {
System.out.println("File not found in Dbcp --> constructor." + f.getMessage());
f.printStackTrace();
}
catch(IOException ioex){
System.out.println("Error I/O in Dbpc --> constructor." + ioex.getMessage());
ioex.printStackTrace();
}
catch(Exception e) {
System.out.println("Error in Dbpc --> constructor." + e.getMessage());
e.printStackTrace();
}
driver = props.getProperty("driver");
url = props.getProperty("url");
login = props.getProperty("login");
password = props.getProperty("password");
maxConnections = (new Integer(props.getProperty("maxConnections"))).intValue();
maxWait = (new Long(props.getProperty("maxWait"))).longValue();
ds = setupDataSource();
}
public static Dbcp getInstance() {
if(instance == null) {
instance = new Dbcp();
}
return instance;
}
public Connection getConn() throws SQLException {
return ds.getConnection();
}
private DataSource setupDataSource() {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(driver);
ds.setUsername(login);
ds.setPassword(password);
ds.setUrl(url);
ds.setMaxActive(maxConnections);
ds.setMaxWait(maxWait);
ds.setDefaultAutoCommit(false);
return ds;
}
public void printDataSourceStats() throws SQLException {
BasicDataSource bds = (BasicDataSource) ds;
System.out.println("NumActive: " + bds.getNumActive());
System.out.println("NumIdle: " + bds.getNumIdle());
}
public void shutdown() throws SQLException {
BasicDataSource bds = (BasicDataSource) ds;
bds.close();
}
}[/code]
Estou usando dbcp… então tenho as API commons.dbcp, commons.pool e commons.collections do Jakarta.
Nota que não estou fazendo muito no main… só estou testando pra ver se tá tudo bem… e não está.