package com.hibernate;import com.mysql.jdbc.Connection;
import java.sql.*;public class mysqlconn {    public static Connection getConn(){
String driverName="com.mysql.jdbc.Driver";
String user="root";
String password="password";
Connection conn=null;
String url="jdbc:mysql://localhost:3306/hibernate";
try{
Class.forName(driverName);
System.out.println("Start connection database.....");
conn=(Connection) DriverManager.getConnection(url, user, password);
System.out.println("connection database fall.");
}catch(Exception e){
e.printStackTrace();
}
return conn;
}
public static void main(String[] args) {
try {
Statement statement= mysqlconn.getConn().createStatement();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Statement statement= mysqlconn.getConn().createStatement(); 这行的statement 我明明已经赋值
The local variable statement is never read.

解决方案 »

  1.   

    The local variable statement is never read.
    你的错误信息是这个吗?这个应该只是一个警告吧?
      

  2.   

    他说你的本地变量statement一直没有使用.
    你所说的赋值不等用使用.除非调用他的方法或属性
      

  3.   

      你的程序有问题,如果Statement statement= mysqlconn.getConn().createStatement();   getConn()返回为空,就会抛出null exception。 
    The local variable statement is never read. 这个应该是IDE的提示吧,可以不用管他。
      

  4.   

    因为你statement只是简单的被赋值而没有使用,报的一个警告而已,不用管他
      

  5.   

    但是程序不能连接数据库.不知道为什么,mysql已经被开启了.....
      

  6.   

    看看端口号
    SQL服务器是否打开
    密码是否设置正确
    不应用static吧?
      

  7.   

    就是你没有用statement这个 variable, 这个只是eclips的提示,没有什么问题。
    如果你用statement.executeQuery("select * from table");
    就没问题,你可以试一下,