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.
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.
你的错误信息是这个吗?这个应该只是一个警告吧?
你所说的赋值不等用使用.除非调用他的方法或属性
The local variable statement is never read. 这个应该是IDE的提示吧,可以不用管他。
SQL服务器是否打开
密码是否设置正确
不应用static吧?
如果你用statement.executeQuery("select * from table");
就没问题,你可以试一下,