繁体   English   中英

未使用局部变量conn的值

[英]The value of the local variable conn is not used

正如我在主题上提到的那样,我面临着警告“未使用局部变量conn的值”

我在编码中清楚地使用了变量,但是它向我显示了这种类型的错误。 如果您可以就此提出建议,将不胜感激。

[码]

package jdbc;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

public class example {
    public static void main(String[] ar) {


        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("Success to find Driver");
        }catch(ClassNotFoundException e) {
            System.err.println("error = Failed to find driver");
        }//*Find MYSQL driver

        Connection conn = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/class", "root", "****");
            System.out.println("Connected to MySql");
        } catch (SQLException e) {
            System.err.println("error = Failed to Create connection");
        }//* Creating Connection

        }
    }

[运行后结果]

成功找到驱动程序错误=无法建立连接

在您的代码中,您已为conn分配了一个引用,但是您没有在任何地方使用该对象,因此发出警告

要消除该警告,请在某个地方使用该警告(也许在某处进行sysout )或添加@SuppressWarnings("unused")批注

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM