I'm trying to connect to oracle 11c and the connection is not made. Give the error:
ES Error: Got one from a read call
I'm testing the query in a servlet, I'm still not looking for the form. Let's see:
package connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connect {
public static Connection conexao;
private static String servidor = "jdbc:mysql://127.0.0.1:3128/";
public static boolean conectar() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conexao = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:3128:xe", "andre", "root");
if (conexao == null) {
return false;
}
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return true;
}
}
Code to do the query:
package hospede;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import connection.Connect;
//@WebServlet("/Hospede")
public class Hospede extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
testar();
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
private static void testar() {
boolean conectado=Connect.conectar();
String query = "select * from hospede";
Statement busca = null;
try {
if (Connect.conexao!=null) {
busca = Connect.conexao.createStatement();
ResultSet resultado = busca.executeQuery(query);
System.out.println(resultado.getString("nome"));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
Note: On line conexao = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:3128:xe", "andre", "root");
What xe
is the type of service? The file I downloaded is ojdbc6.jar.