question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JDBC prepared statement returns NullPointerException

See original GitHub issue

Expected behavior and actual behavior

Calling a prepared statement via jdbc interface returns NullPointerException

Exception in thread “main” java.lang.NullPointerException at com.orientechnologies.orient.jdbc.OrientJdbcResultSetMetaData.getColumnType(OrientJdbcResultSetMetaData.java:192) at TestOrientdb.main(TestOrientdb.java:42)

A prepared statement should work without problems via jdbc interface.

Steps to reproduce the problem

Using the default database:

      OrientJdbcConnection conn = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:" + dbUrl, info); 

      //create and execute statement 
      String stmtStr = "SELECT FROM V WHERE song_type like ?";


      PreparedStatement stmt = conn.prepareStatement(stmtStr);
      stmt.setString(1, "original");

      ResultSet rs = stmt.executeQuery();

      int type = rs.getMetaData().getColumnType(1);

Important Questions

Runninng Mode

  • Embedded, using PLOCAL access mode
  • Embedded, using MEMORY access mode
  • [ X] Remote

Misc

  • I have a distributed setup with multiple servers. How many?
  • I’m using the Enterprise Edition

OrientDB Version

  • v2.0.x - Please specify last number:
  • v2.1.x - Please specify last number:
  • [X ] v2.2.x - Please specify last number: 0

Operating System

  • Linux
  • [X ] MacOSX
  • Windows
  • Other Unix
  • Other, name?

Java Version

  • 6
  • 7
  • [ X] 8

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
Mzed-mancommented, Nov 21, 2019

Check if you have included the mysql-jdbc-connector or the connector to your database library into your project.

0reactions
robfrankcommented, Sep 12, 2016

No, sorry, is the javadoc from ResutlSet.getMetadata:

 /**
     * Retrieves the  number, types and properties of
     * this <code>ResultSet</code> object's columns.
     *
     * @return the description of this <code>ResultSet</code> object's columns
     * @exception SQLException if a database access error occurs or this method is
     *            called on a closed result set
     */
    ResultSetMetaData getMetaData() throws SQLException;

The problem is that at the JDBC level we don’t have all the info about the documents retrieved from Orient. And even if you work with plain OrientDB API what you get as a query result is a list od ODocuments, nothing more. On 3.0 we are working to overcome this, providing more metadata about the documents set returned by the database.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - PreparedStatement throws NullPointerException
The problem is you never initialize conn . For instance, where you do this: Connection myConnection2 = dataSource.
Read more >
Null Pointer Exception on stmt = conn.prepareStatement( query )
You set that to something in the previous line of code, so you must be setting it to null. Therefore the expression "DBConnection....
Read more >
NullPointerException in PreparedStatement... - CodeRanch
The con is set in dbmodel.java and i extends that file with this file inorder to access the DB methods such as Statement,...
Read more >
92089: PreparedStatement.setTimestamp NullPointerException
setTimestamp throws NPE if getParameterMetaData() is called before the statement is executed. This happens in 5.1.47. Rolling back to 5.1.46 ...
Read more >
How to deal with NullPointerException in Java with Examples
Another common cause of NullPointerException is in JDBC code, where you set the parameter for calling stored procedure using CallableStatement or setting ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found