我试图让我的程序能够运行多次。这意味着如果我在我的程序中输入一些内容然后将其关闭,当我启动它时,在 MySQL 的帮助下该信息仍然存在。我对 Java 和 MySQL 还很陌生,但这非常重要。我的程序运行良好,但我不知道如何让 MySQL 保存数组列表。我已经用我需要的一切设置了数据库。到目前为止,这是我的 MySQL 桥:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class SQL {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://instance23389.db.xeround.com:15296/Inventory","user","password");
PreparedStatement Statement = con.prepareStatement("Select * from name");
ResultSet result = Statement.executeQuery();
{
while(result.next())
{
}
}
}
这行:
Class.forName("com.mysql.jdbc.Driver");
throws "Syntax error on token ""com.mysql.jdbc.Driver"", delete this token"
我已经为桥导入了正确的文件。
我还尝试了以下代码。它运行没有错误,但它没有从数据库中导入信息。我从那里去哪里?
public static void main(String[] args) throws SQLException
{
Connection con = DriverManager.getConnection("jdbc:mysql://instance23389.db.xeround.com:15296/Inventory","user","password");
PreparedStatement Statement = con.prepareStatement("Select * from inventory");
ResultSet result = Statement.executeQuery();
while(result.next()) {
// do something with the row
}
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
int x=0;
int choice;
do{
do
{
System.out.println("Please select what you would like to do:\n1 = Add New\n2 = Update Inventory\n3 = Lookup Inventory\n4 = Make Changes\n5 = Totals");
choice=input.nextInt();
if(choice<1 || choice>5)
{
System.out.println("Please enter a number 1-5.");
}
else
{
}
}while(choice<1 || choice>5);
if(choice==1)
{
Product_Chart.newInv();
}
else if(choice==2)
{
Product_Chart.updateInv();
}
else if(choice==3)
{
Product_Chart.lookupInv();
}
else if(choice==4)
{
Product_Chart.MakeChanges();
}
else if(choice==5)
{
Product_Chart.Totals();// TODO does not call Product_Chart.Totals();
}
else
{
System.out.println("Error 101");
}
}while(x==0);
}
}