test query

This commit is contained in:
Luca Conte 2023-11-13 13:50:21 +01:00
parent b70127865e
commit b14c87f0c9
2 changed files with 28 additions and 1 deletions

View File

@ -1,10 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="/home/local/Downloads/sqlite-jdbc-3.43.2.2.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/local/Downloads/slf4j-api-1.7.36.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

17
bonus-1/src/Main.java Normal file
View File

@ -0,0 +1,17 @@
import java.sql.*;
public class Main {
public static void main(String[] args) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:/home/local/sqlite-test.db")) {
System.out.println("Connection successful.");
PreparedStatement s = conn.prepareStatement("SELECT * FROM test;");
ResultSet r = s.executeQuery();
while (r.next()) {
System.out.println(r.getInt("id") + " | " + r.getString("name"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}