当前位置:网站首页>Class. Forname connection MySQL driver keeps throwing classnotfoundexception exception solution
Class. Forname connection MySQL driver keeps throwing classnotfoundexception exception solution
2022-06-12 10:26:00 【Zi Jiao】
Class.forName Connect mysql Drive keeps throwing ClassNotFoundException abnormal , The solution is as follows :
One 、 take mysql-connector-java-5.1.47.jar Copied to the WebContent\WEB-INF\lib Directory . as follows :
C:\Software\java\workspaces\web1\myweb1\WebContent\WEB-INF\lib\mysql-connector-java-5.1.47.jar
Two 、 Right click on the item - Properties - Java Build Path - Libraries - Add JARs - JAR Selection -
find mysql-connector-java-5.1.47.jar - OK - Apply - OK

3、 ... and 、 Connect MySQL normal , All the following codes .

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<table border="1">
<%
String url = "jdbc:mysql://127.0.0.1:3306/mysqldbname?useUnicode=true&characterEncoding=utf8";
String user = "root";
String password = "root";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,user,password);
if ( con.isClosed() ) {
out.println( "failed to connect the database");
return;
}
Statement statement = con.createStatement();
String sql = "SELECT * FROM `users`";
ResultSet rs = statement.executeQuery(sql);
String category = null;
String id = null;
String name = null;
String value = null;
while( rs.next() ){
category = rs.getString("category");
id = rs.getString("id");
name = rs.getString("name");
value = rs.getString("value");
out.println("<tr>");
out.println("<td>" + id + "</td>");
out.println("<td>" + name + "</td>");
out.println("<td>" + value + "</td>");
out.println("<td>" + category + "</td>");
out.println("</tr>");
}
rs.close();
con.close();
out.println( "succeeded connecting to the database");
}catch(SQLException e){
e.printStackTrace();
}
%>
</table>
</body>
</html>
边栏推荐
- PHP wechat red packet allocation logic
- Timers in golang
- 高通平台如何修改特殊电压
- Global and local existence of array, integer and character variables
- Unable to load dynamic library ‘oci8_ 12C 'or unable to load dynamic library' PDO_ OCI 'or cannot find module
- Pycharm view the current version of opencv
- 4. creator mode
- Vscode code debugging skills
- 【机器学习】基于鸢尾花(iris)数据集的逻辑回归分类实践
- conda 安装tensorflow 测试tensorflow
猜你喜欢

2022淘宝618超级喵运会玩法来了 超级喵运会有哪些攻略方法

MySQL user and permission management, role management

【实验】MySQL主从复制及读写分离

properties中文乱码

Redis (II) Memory mapped data structure

Love and hate in the Jianghu

3. Abstract Factory

JVM (V) Virtual machine class loading (parental delegation mechanism)

2022淘宝618超级喵运会怎么玩?2022淘宝618喵运会玩法技巧

Implementation principle of redisson distributed lock
随机推荐
Remote desktop cannot copy and paste solution
What can QA do in a "de QA" project?
PostgreSQL uses stored procedures to splice multiple tables and query data
4. creator mode
conda 安装tensorflow 测试tensorflow
【实验】MySQL主从复制及读写分离
Chromebook system without anti-virus software
PHP curl function
JVM (VIII) Thread safety and lock optimization
[CEGUI] concept introduction
性能指标的信仰危机
[Wayland] Wayland introduction and customized guidance
JVM (VI) Virtual machine bytecode execution engine (with stack execution process and bytecode instruction table)
Solution to the problem that the applet developer tool cannot input simplified Chinese
Propagation of transactions
QT custom window fillets
Quickly build oncyber io
How to play the 2022 Taobao 618 Super Cat Games? What are the strategies for the Super Cat Games
How to implement Web3.0 and digital fashion?
[Wayland] Weston startup process analysis