fodora lianjie mysql_fedora下jsp连接mysql的问题com.mysql.jdbc.Driver

MYSQL

错误:

HTTP Status 500 - Unable to compile class for JSP:

type Exception report

message Unable to compile class for JSP:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [14] in the generated java file: [/usr/share/tomcat/work/Catalina/localhost/_/org/apache/jsp/test/mysql2_jsp.java]

Only a type can be imported. com.mysql.jdbc.Driver resolves to a package

Stacktrace:

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)

org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)

org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)

javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.

Apache Tomcat/7.0.42

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import java.sql.; public class lianjie { // JDBC连接MySQL的URL、用户名和密码 static final String JDBC_URL = "jdbc:mysql://localhost:3306/sys?serverTimezone=GMT%2B8&useSSL=false"; static final String USERNAME = "root"; static final String PASSWORD = "zoushenyu"; public static void main(String[] args) throws SQLException { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { // 连接MySQL数据库 conn = DriverManager.getConnection(JDBC_URL, USERNAME, PASSWORD); // 插入数据 stmt = conn.createStatement(); String sql = "INSERT INTO guoguan (id, name, age, birthday, salary) VALUES (105, '张三', 20, '2000-01-01', 4300)"; stmt.executeUpdate(sql); // 修改数据 sql = "UPDATE guoguan SET salary = 4500 WHERE id = 105"; stmt.executeUpdate(sql); // 删除数据 / sql = "DELETE FROM guoguan WHERE id = 105"; stmt.executeUpdate(sql);*/ // 查询数据 sql = "SELECT * FROM guoguan"; rs = stmt.executeQuery(sql); while (rs.next()) { int id = rs.getInt("id"); String name = rs.getString("name"); int age = rs.getInt("age"); Date birthday = rs.getDate("birthday"); double salary = rs.getDouble("salary"); System.out.printf("%d %s %d %s %.2f\n", id, name, age, birthday.toString(), salary); } } catch (SQLException e) { e.printStackTrace(); } finally { // 释放资源 if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } } } use sys; create table guoguan( id int, name varchar(40), age int, birthday date, salary double ); select * from guoguan; 请为这两份代码写一段说明文档,要尽量详细
最新发布
06-10
这两份代码分别为Java语言编写的与MySQL数据库交互的程序和MySQL数据库中的相关操作语句。 Java程序中,首先定义了连接MySQL数据库所需要的URL、用户名和密码,然后通过调用DriverManager.getConnection()方法连接MySQL数据库。接着,使用Statement对象执行SQL语句,包括插入数据、修改数据、删除数据和查询数据。在查询数据时,通过ResultSet对象获取查询结果,并将结果输出到控制台。 MySQL语句中,首先通过use语句选择了sys数据库,然后通过create table语句创建了一个名为guoguan的表,包括id、name、age、birthday和salary五个字段。接着,通过select语句查询了guoguan表的全部数据。 对于Java程序的说明,需要注意以下几点: 1. 首先需要导入java.sql包,该包提供了与数据库交互所需要的类和接口。 2. 在连接MySQL数据库时,需要使用JDBC URL,该URL由协议名称、主机名、端口号和数据库名称组成,同时还可以设置时区和是否使用SSL等参数。 3. 在执行SQL语句时,需要使用Statement对象或PreparedStatement对象,前者适用于静态SQL语句,后者适用于动态SQL语句。 4. 在处理查询结果时,需要使用ResultSet对象,通过调用其getXXX()方法获取其中的数据。 5. 最后需要释放资源,包括ResultSet对象、Statement对象和Connection对象。 对于MySQL语句的说明,需要注意以下几点: 1. 首先需要选择要操作的数据库,可以使用use语句。 2. 在创建表时,需要指定表名和各个字段的名称、数据类型和约束条件等。 3. 在查询数据时,可以使用select语句,可以指定查询的字段、条件和排序等。 4. 在插入、修改和删除数据时,需要使用insert语句、update语句和delete语句,需要指定要操作的表、要修改的字段和对应的值、要删除的条件等。 5. 最后需要注意语句的语法和语义,避免出现错误或不必要的操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值