プログラムを複数回実行できるようにしようとしています。つまり、プログラムに何かを入力してからシャットダウンした場合、バックアップを開始すると、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);
}
}