当我想从databaseMetaData获取表时,我收到此错误:
Exception in thread "main" java.sql.sqlException: Table name pattern can not be NULL or empty.
at com.MysqL.cj.jdbc.exceptions.sqlError.createsqlException(sqlError.java:545)
at com.MysqL.cj.jdbc.exceptions.sqlError.createsqlException(sqlError.java:513)
at com.MysqL.cj.jdbc.exceptions.sqlError.createsqlException(sqlError.java:505)
at com.MysqL.cj.jdbc.exceptions.sqlError.createsqlException(sqlError.java:479)
at com.MysqL.cj.jdbc.DatabaseMetaData.getTables(DatabaseMetaData.java:3836)
at FindUserTables.main(FindUserTables.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
这是我的代码,我的jdbc驱动是MysqL-connector-java-6.0.5-bin.jar.发生了什么?
import java.sql.*;
public class FindUserTables {
public static void main(String[] args)
throws sqlException,ClassNotFoundException {
Class.forName("com.MysqL.cj.jdbc.Driver");
System.out.println("Driver loaded");
Connection connection = DriverManager.getConnection("jdbc:MysqL://localhost/javabook ?characterEncoding=utf8&useSSL=false&&serverTimezone=UTC","root","123456");
System.out.println("Database connected");
DatabaseMetaData dbMetaData = connection.getMetaData();
ResultSet rsTables = dbMetaData.getTables(null,null,new String[] {"TABLE"});
System.out.print("User tables: ");
while (rsTables.next())
System.out.print(rsTables.getString("TABLE_NAME") + " ");
connection.close();
}
}
最佳答案
原文链接:https://www.f2er.com/mysql/434127.html