Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Xuxue1 opened this issue Dec 11, 2018 · 15 comments
Open

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

Xuxue1 opened this issue Dec 11, 2018 · 15 comments

Comments

@Xuxue1
Copy link

Xuxue1 commented Dec 11, 2018

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!!

@bylee5
Copy link
Contributor

bylee5 commented Dec 12, 2018

@Xuxue1
I ran that code without any problems.

@Xuxue1
Copy link
Author

Xuxue1 commented Dec 12, 2018

I run print
22
Error

@Xuxue1
Copy link
Author

Xuxue1 commented Dec 12, 2018

Dirver version 1.4.2 .

@bylee5
Copy link
Contributor

bylee5 commented Dec 12, 2018

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

@Xuxue1
Copy link
Author

Xuxue1 commented Dec 12, 2018

Can you show your code?

@Xuxue1
Copy link
Author

Xuxue1 commented Dec 12, 2018

ex

@Xuxue1
Copy link
Author

Xuxue1 commented Dec 12, 2018

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

I tried many times。

@bylee5
Copy link
Contributor

bylee5 commented Dec 12, 2018

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

}`

@Xuxue1
Copy link
Author

Xuxue1 commented Dec 12, 2018

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
Copy link
Author

Xuxue1 commented Dec 12, 2018

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

@bylee5
Copy link
Contributor

bylee5 commented Dec 13, 2018

@Xuxue1
Can you tell me what the problem is?

@Xuxue1
Copy link
Author

Xuxue1 commented Dec 13, 2018

Just run my code not modify!

@bylee5
Copy link
Contributor

bylee5 commented Dec 13, 2018

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

@Xuxue1
Copy link
Author

Xuxue1 commented Dec 13, 2018

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

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

@protodef
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants