agensgraph-jdbc icon indicating copy to clipboard operation
agensgraph-jdbc copied to clipboard

I'm find a bug when write data to agensgraph.

Open Xuxue1 opened this issue 6 years ago • 15 comments

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 avatar Dec 11 '18 13:12 Xuxue1

@Xuxue1 I ran that code without any problems.

bylee5 avatar Dec 12 '18 00:12 bylee5

I run print
22 Error

Xuxue1 avatar Dec 12 '18 01:12 Xuxue1

Dirver version 1.4.2 .

Xuxue1 avatar Dec 12 '18 01:12 Xuxue1

@Xuxue1 My output: 22 tt[3.1]{"id": 22}

bylee5 avatar Dec 12 '18 04:12 bylee5

Can you show your code?

Xuxue1 avatar Dec 12 '18 08:12 Xuxue1

ex

Xuxue1 avatar Dec 12 '18 08:12 Xuxue1

  1. Must setAutoCommit = false 2.Create Vertex must return a element 3.Must user placeholder when write and read

I tried many times。

Xuxue1 avatar Dec 12 '18 08:12 Xuxue1

@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){}
    }
}

}`

bylee5 avatar Dec 12 '18 09:12 bylee5

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){}
        }

Xuxue1 avatar Dec 12 '18 09:12 Xuxue1

Can you try this code? This is a strange problem !!

Xuxue1 avatar Dec 12 '18 09:12 Xuxue1

@Xuxue1 Can you tell me what the problem is?

bylee5 avatar Dec 13 '18 00:12 bylee5

Just run my code not modify!

Xuxue1 avatar Dec 13 '18 01:12 Xuxue1

@Xuxue1 My output: 27 tt[3.1]{"id": 27}

bylee5 avatar Dec 13 '18 02:12 bylee5

Don't modify my code then try it . I test the bug about a day. I find other way solved the problem.

我测试这个问题测试了很长时间 这个bug出现的条件很苛刻,你必须不修改我的代码才能复现。

Xuxue1 avatar Dec 13 '18 03:12 Xuxue1

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.

protodef avatar Dec 13 '18 03:12 protodef