With SQLite JDBC wrapper, I can not get values with "table.column"
format. It is wrong, because I can not use
SELECT * from table AS t1, table AS t2 WHERE t1.value<t2.value
It works well with MySQL and even with SQLite+PHP.
Sorry my english.
See this example:
-------------------------------------------------------------------------------------------------
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* @author FARKAS, Máté
* @version 2008.05.10. 11:54:47
*/
public class SQLiteTest {
private final static String MySQLDatabase = "//localhost:8508/
javatest?user=root";
private final static String SQLiteDatabase = ":memory:";
private Connection connection;
private SQLiteTest() throws SQLException {
if (1 == 1) {
loadDriver("SQLite");
} else {
loadDriver("MySQL");
}
createDatabase();
crossJoinTest();
}
private void crossJoinTest() throws SQLException {
ResultSet rs = connection.createStatement().executeQuery(
"SELECT * FROM sqlitetest p1, sqlitetest p2 "
+ "WHERE p1.value = p2.value AND p1.id < p2.id");
System.out.println("Pairs:");
while (rs.next()) {
int first = rs.getInt("p1.id");
int second = rs.getInt("p2.id");
System.out.println(first + " - " + second);
}
}
private void createDatabase() throws SQLException {
Statement statement = connection.createStatement();
try {
statement.executeUpdate("DROP TABLE sqlitetest");
} catch (Exception e) {}
statement.executeUpdate("CREATE TABLE sqlitetest "
+ "(id INTEGER PRIMARY KEY, value INTEGER)");
statement.executeUpdate("INSERT INTO sqlitetest VALUES (1,1)");
statement.executeUpdate("INSERT INTO sqlitetest VALUES (2,1)");
statement.executeUpdate("INSERT INTO sqlitetest VALUES (3,2)");
statement.executeUpdate("INSERT INTO sqlitetest VALUES (4,2)");
statement.executeUpdate("INSERT INTO sqlitetest VALUES (5,3)");
statement.executeUpdate("INSERT INTO sqlitetest VALUES (6,3)");
}
private void loadDriver( String driverName ) {
try {
if (driverName.toLowerCase().equals("sqlite")) {
Class.forName("org.sqlite.JDBC");
connection =
DriverManager.getConnection("jdbc:sqlite:"
+ SQLiteDatabase);
System.out.println("SQLite loaded successful!");
} else {
Class.forName("com.mysql.jdbc.Driver");
connection =
DriverManager.getConnection("jdbc:mysql:" +
MySQLDatabase);
System.out.println("MySQL loaded successful!");
}
} catch (Exception e) {
throw new RuntimeException("Cannot load " + driverName
+ "!", e);
}
}
public static void main( String[] args ) throws Exception {
new SQLiteTest();
}
}
--~--~---------~--~----~------------~-------~--~----~
Mailing List: http://groups.google.com/group/sqlitejdbc?hl=en
To unsubscribe, send email to [EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---