1
I am trying to connect on oracle 11 c and the connection is not performed. Gives error:
ES Error: Got Minus one from a read call >
I’m testing the query in a Servlet, I’m not searching for the form yet. 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 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 the line conexao = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:3128:xe", "andre", "root");
The xe
is the type of service? The file I downloaded is ojdbc6.jar.
Hi André, let’s try to break the problem into smaller pieces. What error do you get when trying to connect? Can connect from some other client (e.g., SQL Developer) from your machine to the host?
– Anthony Accioly
!Anthony Accioly can connect to the oracle command screen.
– André Nascimento
Your
"jdbc:oracle:thin:@host:3128:nome do serviço"
is exactly like this in the program or you puthost
andnome do serviço
here in substitution for what is true in your code to hide confidential details?– Victor Stafusa
@Victor Stafusa nothing to hide. I didn’t know what this service is, so I didn’t put it in properly. I’ve already edited the code.
– André Nascimento
Try the following
jdbc:oracle:thin:@//localhost:1521:xe
(unless you have changed the standard door). Something else, instead of printing thegetMessage()
try to get the entire stack trace (e.printStackTrace()
).– Anthony Accioly
@Anthony Accioly the door I changed because I was using the 8080 and was giving conflict with the Tomcat.
– André Nascimento
André, http port and connection port are different. See the link of the comment above (you find the connection port in the file
listener.ora
).– Anthony Accioly