1
I do not know if it is correct and if it works, but I realized a division in the project. a project would access the DAO and have the connection and a properties file with the connection information. Another has a main class in which I haven’t created frames yet, just a main class for testing. In libraries I added the projects as reference and I did the test but is giving an error where can not read the properties file, could tell me what can be?
Description of the Error:
jul 27, 2016 9:30:41 AM Conection.GenericConnection getDbProperties
GRAVE: null
java.io.FileNotFoundException: src\properties\conf.properties (O sistema não pode encontrar o caminho especificado)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at Conection.GenericConnection.getDbProperties(GenericConnection.java:25)
at Conection.OracleConnection.getConnection(OracleConnection.java:35)
at Views.mainTeste.main(mainTeste.java:16)
Exception in thread "main" java.lang.NullPointerException
at Conection.OracleConnection.getConnection(OracleConnection.java:35)
at Views.mainTeste.main(mainTeste.java:16)
D:\SICF_Project\SICFCadastros\nbproject\build-impl.xml:1063: The following error occurred while executing this line:
D:\SICF_Project\SICFCadastros\nbproject\build-impl.xml:804: Java returned: 1
FALHA NA CONSTRUÇÃO (tempo total: 0 segundos)
Class Mother Genericconnection
package Conection;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Ulisses Gimenes
*/
public abstract class GenericConnection {
protected Properties dbProperties;
protected Connection conn;
protected Statement st;
public Properties getDbProperties() {
if (dbProperties == null) {
try {
dbProperties.load(new FileInputStream("src/properties/conf.properties"));
} catch (FileNotFoundException ex) {
Logger.getLogger(GenericConnection.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(GenericConnection.class.getName()).log(Level.SEVERE, null, ex);
}
}
return dbProperties;
}
public void setDbProperties(Properties dbProperties) {
this.dbProperties = dbProperties;
}
public Connection getConn() {
return conn;
}
public void setConn(Connection conn) {
this.conn = conn;
}
public Statement getSt() {
return st;
}
public void setSt(Statement st) {
this.st = st;
}
public abstract Connection getConnection();
}
Connection class for oracle
package Conection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author UlissesGimenes
*/
public class OracleConnection extends GenericConnection {
private static OracleConnection connOra;
public static OracleConnection getConnOra() {
if(connOra == null){
connOra = new OracleConnection();
}
return connOra;
}
public static void setConnOra(OracleConnection connOra) {
OracleConnection.connOra = connOra;
}
@Override
public Connection getConnection() {
if (getConn() != null) {
return getConn();
} else {
try {
String url = "jdbc:oracle:thin:@" +
super.getDbProperties().getProperty("ServerOracle") +
":" + super.getDbProperties().getProperty("portOracle") +
":" + super.getDbProperties().getProperty("sidOracle");
setConn(DriverManager.getConnection(
url,
super.getDbProperties().getProperty("userOracle"),
super.getDbProperties().getProperty("passwdOracle")));
setSt(getConn().createStatement());
System.out.println("conectado");
return getConn();
} catch (SQLException ex) {
Logger.getLogger(OracleConnection.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
}
}
Main class of testing
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Views;
import Conection.OracleConnection;
/**
*
* @author UlissesGimenes
*/
public class mainTeste {
public static void main(String[] args) {
OracleConnection.getConnOra().getConnection();
}
}
Image of the tree of the project
When formatting code, use the shortcut
{}
to format the code, since the snippet is for html, javascript or css. Add the image directly here, the link may not be accessible for some people.– user28595
Yes, Thank you...
– Ulisses Gimenes
I had forgotten, of a new Properties();, as I also could not recognize the properties folder, I put it inside the project that will be executed.
– Ulisses Gimenes
diegofm, In the comments, I can put the link to an image..
– Ulisses Gimenes
Recommended is to insert directly into the question.
– user28595
thanks, thanks...
– Ulisses Gimenes