我有一个问题,我想有人可以帮助我,因为我有点困惑。 我编写了一个程序,在其中读取 Excel 文件并将其数据存储在数据库中。 在此数据库中,每个 Excel 文件创建一个表。我已经编写了程序,到目前为止一切正常。现在,在我完成连接之后,我希望用户能够提供将在客户端中读取的文件的完整路径,然后继续程序的其余部分,读取数据并将它们存储在 table 。谁能帮助我如何做到这一点?下面是连接代码。
public static void main (String[] args) throws Exception {
try {
System.out.println("get the connection");
}
catch( Exception e )
{
System.out.println( "SQLException: " + e.getMessage() );
}
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection(
"jdbc:mysql://localhost:3306/kainourgia", "root", "root");
DatabaseMetaData meta = (DatabaseMetaData) con.getMetaData();
ResultSet res = meta.getCatalogs();
System.out.println("List of the databases: ");
while (res.next()){
System.out.println (" " +res.getString(1));
}
//String filename = "C:\\Users\\myfiles\\Documents\\test5.xls";
String fullPath = "C:\\Users\\myfiles\\Documents\\test5.xls";
String Path = "C:\\Users\\myfiles\\Documents\\";
String filename = "test5.xml";
String[] parts = filename.split("\\.");
String tablename = parts[0];
有人可以帮助我吗?
最佳答案
您可以将文件名作为命令行参数传递给 java 程序,例如
<强> java <classname> <filepath>
或者
您可以从stad输入中读取用户提供的文件路径
关于java - 用户如何使用 java 给出文件的完整路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16232535/