Skip to content

Commit 684e567

Browse files
committed
Section 28 JDBC Using SQLite
Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent 6178d89 commit 684e567

File tree

5 files changed

+28
-235
lines changed

5 files changed

+28
-235
lines changed

Section28JDBCusingSQLite/SQL Practice 1.txt

Lines changed: 0 additions & 98 deletions
This file was deleted.

Section28JDBCusingSQLite/SQL Practice.txt

Lines changed: 0 additions & 132 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class JDBCUsingSQLite {
2+
public static void main(String[] args) {
3+
System.out.println("SQLite Setup Mac & Window");
4+
}
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.nio.file.Path;
2+
import java.nio.file.Paths;
3+
import java.sql.*;
4+
public class SqliteJdbcTest {
5+
public static void main(String[] args) {
6+
Path dbPath = Paths.get("/Users","somesh","Java SE","JavaEvolution-Learning-Growing-Mastering","Section28JDBCusingSQLite","test.db");
7+
String url = "jdbc:sqlite:" + dbPath.toString();
8+
System.out.println("JDBC URL: " + url);
9+
try {
10+
Class.forName("org.sqlite.JDBC");
11+
try (Connection conn = DriverManager.getConnection(url)) {
12+
System.out.println("Connected (driver: " + conn.getMetaData().getDriverName() + ")");
13+
try (Statement st = conn.createStatement()) {
14+
st.executeUpdate("CREATE TABLE IF NOT EXISTS student (id INTEGER PRIMARY KEY, name TEXT);");
15+
st.executeUpdate("INSERT INTO student(name) VALUES('Diwan');");
16+
try (ResultSet rs = st.executeQuery("SELECT id, name FROM student;")) {
17+
while (rs.next()) System.out.println("row -> id: " + rs.getInt("id") + ", name: " + rs.getString("name"));
18+
}
19+
}
20+
}
21+
} catch (Exception e) { e.printStackTrace(); }
22+
}
23+
}

Section28JDBCusingSQLite/src/hi.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)