@@ -2,28 +2,30 @@ package com.pgvector
22
33import java .sql .DriverManager
44import com .pgvector .PGvector
5+ import org .junit .Test
56
6- object JDBCScala {
7+ class JDBCScala {
8+ @ Test
79 def example (): Unit = {
810 val conn = DriverManager .getConnection(" jdbc:postgresql://localhost:5432/pgvector_java_test" )
911
1012 val setupStmt = conn.createStatement()
1113 setupStmt.executeUpdate(" CREATE EXTENSION IF NOT EXISTS vector" )
12- setupStmt.executeUpdate(" DROP TABLE IF EXISTS jdbc_items " )
14+ setupStmt.executeUpdate(" DROP TABLE IF EXISTS jdbc_scala_items " )
1315
1416 PGvector .addVectorType(conn)
1517
1618 val createStmt = conn.createStatement()
17- createStmt.executeUpdate(" CREATE TABLE jdbc_items (id bigserial PRIMARY KEY, embedding vector(3))" )
19+ createStmt.executeUpdate(" CREATE TABLE jdbc_scala_items (id bigserial PRIMARY KEY, embedding vector(3))" )
1820
19- val insertStmt = conn.prepareStatement(" INSERT INTO jdbc_items (embedding) VALUES (?), (?), (?), (?)" )
21+ val insertStmt = conn.prepareStatement(" INSERT INTO jdbc_scala_items (embedding) VALUES (?), (?), (?), (?)" )
2022 insertStmt.setObject(1 , new PGvector (Array [Float ](1 , 1 , 1 )))
2123 insertStmt.setObject(2 , new PGvector (Array [Float ](2 , 2 , 2 )))
2224 insertStmt.setObject(3 , new PGvector (Array [Float ](1 , 1 , 2 )))
2325 insertStmt.setObject(4 , new PGvector ())
2426 insertStmt.executeUpdate()
2527
26- val neighborStmt = conn.prepareStatement(" SELECT * FROM jdbc_items ORDER BY embedding <-> ? LIMIT 5" )
28+ val neighborStmt = conn.prepareStatement(" SELECT * FROM jdbc_scala_items ORDER BY embedding <-> ? LIMIT 5" )
2729 neighborStmt.setObject(1 , new PGvector (Array [Float ](1 , 1 , 1 )))
2830 val rs = neighborStmt.executeQuery()
2931 while (rs.next()) {
@@ -32,7 +34,7 @@ object JDBCScala {
3234 }
3335
3436 val indexStmt = conn.createStatement()
35- indexStmt.executeUpdate(" CREATE INDEX jdbc_index ON jdbc_items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)" )
37+ indexStmt.executeUpdate(" CREATE INDEX jdbc_scala_index ON jdbc_scala_items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)" )
3638
3739 conn.close()
3840 }
0 commit comments