【发布时间】:2023-03-17 15:40:01
【问题描述】:
我正在使用 Tomcat 服务器 8
我已经在Lib中添加了Ojdbc7.jar
并使用 Oracle 11g (11.2.0.2) 版本
我的代码是:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class PrintForm extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
//Variables declaration
String emp_name = req.getParameter("name");
String s = "INSERT into Emp values(?,?)";
try{
//Making connection with Oracle
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
//Inserting data into table
PreparedStatement pst = con.prepareStatement(s);
pst.setInt(1,1);
pst.setString(2,emp_name);
pst.executeUpdate();
con.close();
}catch(Exception e){
out.println(e);
}
}
}
这是在扔,
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521:xe
这个例外。
那么我应该使用什么驱动程序或 JDK 版本? 当前版本是 1.7
【问题讨论】:
-
您应该阅读 JDBC 基础教程。这将在第一课中介绍。