JDBC操作MySQL时注意的一些细节
我写出了mysql的查询sql语句,在mysql的数据库客户端上运行一切顺利。注意sql中有含有中文的条件。有一句是 tempTable.type =di
今天我做了一个java接口程序,实现从mysql数据库中取值插入到一个Oracle数据库中。我觉得挺简单的操作,mysql的查询sql写出来了,就没有什么难的了。java中JDBC操作数据库的代码没有太大的变化。但因为一些操作细节没有注意到,浪费了我一下午的时间才搞定。
我的做法是这样的,首先我写出了mysql的查询sql语句,在mysql的数据库客户端上运行一切顺利。注意sql中有含有中文的条件。有一句是 tempTable.type =dinary '利息',查询出来5条记录,mysql的中文查询需要有一个mysql内置的二进制的转换符号。 调试通过,我把sql语句复制到了java的代码中,利用JDBC执行的结果却是0条。我的第一直觉是mysql数据库连接错了吗,但很快我发现,数据库连接是对的,java代码中的sql语句和mysql客户端执行的sql没有任何差别。但客户端和java代码中执行的结果却不一致。
最后问题定位在sql语句中的中文上,java中中文的编码和mysql数据库执行sql时中文编码不一致导致的。
"......";
--然后就是JDBC操作
这样改造完成后,再次执行java代码,搞定,,和数据库客户端sql执行结果一致。
还有一个细节需要说明,我有一次做接口时出现的一个问题。也郁闷了好久。
我写了一个完全正确的一个sql,但执行的结果并不是我要的结果。 其中sql中有一段 max(atable.version)的操作。
因为对方数据库在建atable表的时候 version这个版本字段建成了varchar类型,实际业务中这个版本最大值为22 而我用sql的max函数查询出的结果是 9 这就导致了查询结果的不一致。后来对方数据库atable表的这个version字段修改成了integer类型 才算执行正确。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

This article recommends the top ten digital currency trading apps in the world, including Binance, OKX, Huobi Global, Coinbase, Kraken, Gate.io, KuCoin, Bitfinex, Gemini and Bitstamp. These platforms have their own characteristics in terms of transaction pair quantity, transaction speed, security, compliance, user experience, etc. For example, Binance is known for its high transaction speed and extensive services, while Coinbase is more suitable for novices. Choosing a platform that suits you requires comprehensive consideration of your own needs and risk tolerance. Learn about the world's mainstream digital currency trading platforms to help you conduct digital asset trading safely and efficiently.

This article will provide a detailed introduction to how to install and register a Bitcoin trading application. The Bitcoin trading app allows users to manage and trade cryptocurrencies such as Bitcoin. The article guides users through the installation and registration process step by step, including downloading applications, creating accounts, performing identity verification, and first deposit. The goal of the article is to provide beginners with clear and easy-to-understand guidelines to help them easily enter the world of Bitcoin trading.

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.
