我尝试阅读很多主题,但我没有找到答案。 Plz,一些有光泽的灵魂可以帮助我吗?
代码只有3个文件,使用jsp进行非常简单的查询。
的index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Exercício 01 JDBC</title>
</head>
<body>
<h1>Listagem de Usuário:</h1>
<FORM METHOD="POST" ACTION="App">
<P> Clique em <INPUT TYPE="SUBMIT" VALUE="LISTAR">
para obter a relação do nome do primeiro usuário.</p>
</FORM>
</body>
</html>
App.java
package br.com.yonathan.faculdades.jdbc;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
@WebServlet(name = "App", urlPatterns = {"/App"})
public class App extends HttpServlet {
private Connection con;
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
final String url = "jdbc:oracle:thin:@yyy.inf.poa.ifrs.edu.br:1521:XE";
final String us = "xxx";
try {
Class.forName("oracle.jdbc.OracleDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
try {
con = DriverManager.getConnection(url, us, us);
} catch (SQLException ex) {
throw new ServletException(ex);
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String sql = "SELECT nome FROM JDBC_USUARIO where ROWNUM = 1";
String saida = "";
try (PreparedStatement stm = con.prepareStatement(sql);
ResultSet rs = stm.executeQuery()) {
while (rs.next()) {
saida = rs.getString(1);
}
rs.close();
} catch (SQLException ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
request.setAttribute("resultado", saida);
response.setContentType("text/html;charset=UTF-8");
request.getRequestDispatcher("resposta.jsp").forward(request, response);
}
}
resposta.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Servlet Exibe Resultado</title>
</head>
<body>
<h1>JDBC Connection</h1>
<h2>Primeiro nome cadastrado:</h2>
${resultado}.
</body>
</html>
用户和passwd是相同的。 在发布之前我真的试着修复。
答案 0 :(得分:0)
在oracle安装中查找WebElement element = driver.findElement(By.id("id"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();
或ojdbc6.jar
,并将该文件放入ojdbc7.jar
。然后重启tomcat并再试一次。
答案 1 :(得分:0)
在文件&#34; pom.xml &#34;进入项目文件,我不得不添加:
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
</dependencies>
和
<repositories>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
它有效。 我不知道为什么从一开始就不起作用。这是一个Maven项目,但我必须手动包含&#34;#34;这个东西,然后当我点击运行他下载缺少的驱动程序,似乎工作到现在为止。 谢谢你们!