調査の章を通して自分のやり方で作業し、2つのデータベースが作成されているコードを与えられました。コードをコンパイルして動作します。私はコードをtweekにしようとしていないので、情報を選択して表示すると、データベースが1つしかないのですが、どこから情報が得られないのでしょうか? DBから?Javaデータベースのヘルプ
おかげ
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
public class FootballTeamDataBase
{
Connection connection;
Statement statement;
ResultSet results;
public FootballTeamDataBase()
{
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
}
catch (ClassNotFoundException cnfe)
{
System.err.println("Derby driver not found.");
}
try
{
// What drivers are there?
System.out.println("Available drivers:");
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements())
{
System.out.println(drivers.nextElement());
}
System.out.println();
connection = DriverManager.getConnection
("jdbc:derby://localhost:1527/MusicShop;create=true;user=admin;pass=admin");
statement = connection.createStatement();
try
{
statement.execute("drop table FootballTeam");
}
catch (SQLException e)
{
System.out.println("Table did not previously exist " + e);
}
// Now create the table.
statement.execute("create table " +
"FOOTBALLTEAM(" +
"ID varchar(12) primary key not null, " +
"POSITION varchar(24), " +
"NAME varchar(24),") ;
}
catch (SQLException sqle)
{
System.err.println("Problem:" + sqle);
}
}
public void addData()
{
try
{
statement.execute("insert into FOOTBALLTEAM values " +
"('1',Keeper','Dale'");
statement.execute("insert into FOOTBALLTEAM values " +
"('2',Defender','Lewis'");
statement.execute("insert into FOOTBALLTEAM values " +
"('3','MIDFIELD','Jones'");
}
catch (SQLException sqle)
{
System.err.println("Problem populating data:" + sqle);
}
}
public void showTeam()
{
try
{
// check the contents of the table
System.out.println("DB contents:");
// select all records
statement.execute("select * from FOOTBALLTEAM");
ResultSet results = statement.getResultSet();
while (results.next())
{
System.out.println(results.getString("ID") + " " + results.getString("POSITION") +
" = " + results.getString("NAME"));
}
}
catch (SQLException e)
{
// nothing wrong
}
}
}
それはそのアミット – user445714
感謝をなぜ起こったか知らないフォーマットを修正します申し訳ありませんどのデータベースであるか、プログラムが何をすべきか、入力例と出力(期待される出力と実際の出力)は、この質問をはるかに理解しやすくします。 – user445714
に任意の情報をソートするため – amit