Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Visualizzazione tabelle in Derby

26 views
Skip to first unread message

none

unread,
Apr 19, 2013, 5:56:22 AM4/19/13
to
Salve,
sto cercando di visualizzare una tabella creata nello Schema APP
utilizzando il plugin Database Development di Eclipse ma come risultato
ottengo che la tabella non esiste sebbene io la veda in Data Source
Explorer. Perchè ?
grazie

Questo è il codice :

package myapp;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSetMetaData;


public class Restaurants
{
private static String dbURL = "jdbc:derby:MyDB;create=true";
private static String tableName = "APP.MYTABELLE";
// jdbc Connection
private static Connection conn = null;
private static Statement stmt = null;

public static void main(String[] args)
{
createConnection();
selectRestaurants();
shutdown();
}

private static void createConnection()
{
try
{

Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
//Get a connection
conn = DriverManager.getConnection(dbURL);
}
catch (Exception except)
{
except.printStackTrace();
}
}



private static void selectRestaurants()
{
try
{
stmt = conn.createStatement();
ResultSet results = stmt.executeQuery("select * from " +
tableName);
ResultSetMetaData rsmd = results.getMetaData();
int numberCols = rsmd.getColumnCount();
for (int i=1; i<=numberCols; i++)
{
//print Column Names
System.out.print(rsmd.getColumnLabel(i)+"\t\t");
}


System.out.println("\n-------------------------------------------------");

while(results.next())
{
int id = results.getInt(1);
int restName = results.getInt(2);
String cityName = results.getString(3);
System.out.println(id + "\t\t" + restName + "\t\t" +
cityName);
}
results.close();
stmt.close();
}
catch (SQLException sqlExcept)
{
sqlExcept.printStackTrace();
}
}

private static void shutdown()
{
try
{
if (stmt != null)
{
stmt.close();
}
if (conn != null)
{
DriverManager.getConnection(dbURL + ";shutdown=true");
conn.close();
}
}
catch (SQLException sqlExcept)
{

}

}
}


Come risultato ottengo :

java.sql.SQLSyntaxErrorException: Table/View 'APP.MYTABELLE' does not exist.
at
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown
Source)
at
org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown
Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown
Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown
Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown Source)
at myapp.Restaurants.selectRestaurants(Restaurants.java:75)
at myapp.Restaurants.main(Restaurants.java:23)
Caused by: java.sql.SQLException: Table/View 'APP.MYTABELLE' does not exist.
at
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
Source)
at
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown
Source)
... 10 more
Caused by: ERROR 42X05: Table/View 'APP.MYTABELLE' does not exist.
at org.apache.derby.iapi.error.StandardException.newException(Unknown
Source)
at
org.apache.derby.impl.sql.compile.FromBaseTable.bindTableDescriptor(Unknown
Source)
at
org.apache.derby.impl.sql.compile.FromBaseTable.bindNonVTITables(Unknown
Source)
at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown Source)
at
org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown
Source)
at
org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown
Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown
Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at
org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown
Source)
... 4 more

none

unread,
Apr 19, 2013, 7:13:00 AM4/19/13
to
Ho creato un nuovo progetto e adesso funziona .
Ciao
0 new messages