agensgraph-jdbc
agensgraph-jdbc copied to clipboard
I'm find a bug when write data to agensgraph.
try(Connection connection = dataSource.getConnection()){
connection.setAutoCommit(false);
try(PreparedStatement preparedStatement = connection
.prepareStatement("create (t:TT{id:?}) return t.id as id")){
preparedStatement.setInt(1,22);
try(ResultSet set = preparedStatement.executeQuery()){
if(set.next()){
System.out.println(set.getObject("id"));
}
}
}
try(PreparedStatement preparedStatement = connection
.prepareStatement("match (n:TT{id:?}) return n")){
preparedStatement.setInt(1,22);
try(ResultSet set = preparedStatement.executeQuery()){
if(set.next()){
System.out.println(set.getObject("n").toString());
}else{
System.out.println("Error");
}
}
}
connection.commit();
}
I open a transaction and write a data, but I can't read it!!
@Xuxue1 I ran that code without any problems.
I run print
22
Error
Dirver version 1.4.2 .
@Xuxue1 My output: 22 tt[3.1]{"id": 22}
Can you show your code?

- Must setAutoCommit = false 2.Create Vertex must return a element 3.Must user placeholder when write and read
I tried many times。
@Xuxue1 My test code:
`public class Test { public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("net.bitnine.agensgraph.Driver");
String connectionString = "jdbc:agensgraph://127.0.0.1:4432/postgres";
String username = "bylee";
String password = "bylee";
conn = DriverManager.getConnection(connectionString, username, password);
stmt = conn.createStatement();
stmt.execute("DROP GRAPH IF EXISTS t1 CASCADE");
stmt.execute("CREATE GRAPH t1");
stmt.execute("SET graph_path = t1");
conn.setAutoCommit(false);
try(PreparedStatement preparedStatement = conn
.prepareStatement("create (t:TT{id:?}) return t.id as id")){
preparedStatement.setInt(1,22);
try(ResultSet set = preparedStatement.executeQuery()){
if(set.next()){
System.out.println(set.getObject("id"));
}
}
}
try(PreparedStatement preparedStatement = conn
.prepareStatement("match (n:TT{id:?}) return n")){
preparedStatement.setInt(1,22);
try(ResultSet set = preparedStatement.executeQuery()){
if(set.next()){
System.out.println(set.getObject("n").toString());
}else{
System.out.println("Error");
}
}
}
conn.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
if(rs != null) try{rs.close();}catch(SQLException e){}
if(stmt != null) try{stmt.close();}catch(SQLException e){}
if(conn != null) try{conn.close();}catch(SQLException e){}
}
}
}`
Connection conn=null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("net.bitnine.agensgraph.Driver");
String connectionString = "your url";
String username = "your userName";
String password = "your password";
conn = DriverManager.getConnection(connectionString, username, password);
stmt = conn.createStatement();
// stmt.execute("DROP GRAPH IF EXISTS t1 CASCADE");
// stmt.execute("CREATE GRAPH t1");
stmt.execute("SET graph_path = t1");
stmt.close();
conn.setAutoCommit(false);
try(PreparedStatement preparedStatement = conn
.prepareStatement("create (t:TT{id:?}) return t.id as id")){
preparedStatement.setInt(1,27);
try(ResultSet set = preparedStatement.executeQuery()){
if(set.next()){
System.out.println(set.getObject("id"));
}
}
}
try(PreparedStatement preparedStatement = conn
.prepareStatement("match (n:TT{id:?}) return n")){
preparedStatement.setInt(1,27);
try(ResultSet set = preparedStatement.executeQuery()){
if(set.next()){
System.out.println(set.getObject("n").toString());
}else{
System.out.println("Error");
}
}
}
conn.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
if(rs != null) try{rs.close();}catch(SQLException e){}
if(stmt != null) try{stmt.close();}catch(SQLException e){}
if(conn != null) try{conn.close();}catch(SQLException e){}
}
Can you try this code? This is a strange problem !!
@Xuxue1 Can you tell me what the problem is?
Just run my code not modify!
@Xuxue1 My output: 27 tt[3.1]{"id": 27}
Don't modify my code then try it . I test the bug about a day. I find other way solved the problem.
我测试这个问题测试了很长时间 这个bug出现的条件很苛刻,你必须不修改我的代码才能复现。
Hello @Xuxue1,
I've tried to reproduce the error you reported but I couldn't. When I compiled and ran the last code you posted, it returned the same result with the one @bylee5 posted. I didn't modify the code.
I used the same driver(v1.4.2) and AgensGraph v2.0.