Hallo,
ich habe folgende fehlermeldung, wenn sich meine anwendung mit der datenbank von oracle verbinden will:
"java.sql.SQLException: The Network Adapter cannot establish the connection"
ich verstehe das nicht ganz.
das mein code für die verbindung:
kan mir einer helfen? ich verstehe das nicht.
muss mich mit oracle verbinden, habe auch die entsprechende lib dazu
ich habe folgende fehlermeldung, wenn sich meine anwendung mit der datenbank von oracle verbinden will:
"java.sql.SQLException: The Network Adapter cannot establish the connection"
ich verstehe das nicht ganz.
das mein code für die verbindung:
Code:
/*
* dbSelect.java
*
*
*/
package NameEgal;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
/**
* Sends a query to a SQL database management system and gets the result as a
* result set.
* The connection parameters are stored in a poperties file
*/
public class DbSelect {
private Connection conn = null;
private String sqlQuery;
private String[] args;
private PreparedStatement prepSql;
private Statement stmt;
private ResultSet rSet;
private Properties properties;
private String dbClass;
private String dbUrl;
private String dbUser;
private String dbPasswort;
/**
* Sets the SQL statement from the given parameter.
* @param sqlQuery SQL SELECT statement
*/
public DbSelect(String sqlQuery, String[] args) {
this.sqlQuery = sqlQuery;
this.args = args;
}
public DbSelect(String sqlQuery) {
this.sqlQuery = sqlQuery;
}
/**
* This method initializes the database connection.
* @return null if no exception is thrown,
* otherwise the exception as a string
*/
public String init() {
properties = new Properties();
try {
properties.load(new FileInputStream(System.getProperty("user.dir") +
System.getProperty("file.separator") +
"database.properties"));
dbClass = properties.getProperty("dbClass");
dbUrl = properties.getProperty("dbUrl");
dbUser = properties.getProperty("dbUser");
dbPasswort = properties.getProperty("dbPassword");
} catch (FileNotFoundException ex) {
return ex.toString();
} catch (IOException ex) {
ex.printStackTrace();
return ex.toString();
}
try {
Class.forName(dbClass);
} catch (ClassNotFoundException ex) {
return ex.toString();
}
try {
conn = DriverManager.getConnection(dbUrl, dbUser, dbPasswort);
stmt = conn.createStatement();
prepSql = conn.prepareStatement(sqlQuery);
if (args != null) {
for (int i=0; i < args.length; i++)
{
if (args[i] != null) {
prepSql.setString(i+1, args[i]);
}
}
}
rSet = prepSql.executeQuery();
return null;
} catch (SQLException ex) {
ex.printStackTrace();
return ex.toString();
}
}
/**
* To get the result set from the SELECT query,
* @return the ResultSet
*/
public ResultSet getResultSet() {
return rSet;
}
/**
* Close all database elements: the statement, the result set
* and the connection.
*/
public void closeAll() {
try {
stmt.close();
rSet.close();
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
/**
* Closes the result set.
*/
public void closeRseultSet() {
try {
rSet.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
/**
* Closes the database connection
*/
public void closeConnection() {
try {
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
/**
* Closes the statement.
*/
public void closeStatement() {
try {
stmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
kan mir einer helfen? ich verstehe das nicht.
muss mich mit oracle verbinden, habe auch die entsprechende lib dazu