I already checked the other question about my issue, but none of them solved.
I imported the Neo4j Jar by configuring the build path, but still I get this error.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestNeo4j {
public static void main(String[] args) throws SQLException {
Connection c = DriverManager.getConnection("jdbc:neo4j://localhost:7474/", "neo4j", "neo4j");
Statement st = c.createStatement();
String cql = "match (m)-[:IS_ALLERGIC_TO]->(n:Product) where n.name = 'gluten' return m.name";
ResultSet rs = st.executeQuery(cql);
while(rs.next())
System.out.println(rs.getString(1));
c.close();
}
}
This is my code. Can you figure out what the problem is?
As suggested here, use neo4j jar with dependencies (neo4j-jdbc-2.1.4-jar-with-dependencies.jar).
You can grab it from neo4j release repository, here
Related
I have this code:
package routines;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.Properties;
public class SnowflakeDriverExample {
public static void main() throws Exception
{
System.out.println("Create JDBC connection");
Connection connection = getConnection();
System.out.println("Done creating JDBC connectionn");
}
private static Connection getConnection()
throws SQLException
{
try
{
Class.forName("net.snowflake.client.jdbc.SnowflakeDriver");
}
catch (ClassNotFoundException ex)
{
System.err.println("Driver not found");
}
// build connection properties
Properties properties = new Properties();
properties.put("user", "my_user");
properties.put("password", "my_password");
properties.put("db", "my_db");
properties.put("schema", "my_schema");
// create a new connection
String connectStr = System.getenv("SF_JDBC_CONNECT_STRING");
// use the default connection string if it is not set in environment
if(connectStr == null)
{
connectStr = "https://my_account.snowflakecomputing.com/";
}
return DriverManager.getConnection(connectStr, properties);
}
}
now, when I call:
SnowflakeDriverExample.main();
I get this error:
Exception in component tJava_1 (j_example)
java.sql.SQLException: No suitable driver found for https://my_account.snowflakecomputing.com/
when I iterated over drivers and printed them- I got this one:
net.snowflake.client.jdbc.SnowflakeDriver
looks like I have the correct snowflake driver, and I the connectionStr is my actual snowflake url.
so what's the problem?
ok.
the problem was my connectionStr, which was:
connectStr = "https://my_account.snowflakecomputing.com/";
and should be:
connectStr = "jdbc:snowflake://my_account.snowflakecomputing.com/";
now everything is fine. thanks a lot!
I am trying to connect sqlite db browser with java using nano editor i am very new here. i have
followed some youtube videos but i am stacking at mid can anyone please help
here is my code.
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.SQLException;
public class SqliteDB{
Connection c = null;
Statement stmt = null;
SqliteDB(){
try{
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:signup.db");
System.out.println("Connected to DB");
}
catch(Exception e){
System.out.println("Error: "+ e.getMessage());
}
}
}
Error: org.sqlite.JDBC
thank you guys for helping.
I think that you have not imported library org.sqlite.JDBC in your project, Class.forName() return class that exists, when you get error like this it says that this class is not exists.
First of all download library from: https://bitbucket.org/xerial/sqlite-jdbc/downloads/
Then import in your project and that's how you should write the code:
public static void main(String[] args) throws SQLException {
org.sqlite.JDBC j = new org.sqlite.JDBC();
Connection c = DriverManager.getConnection("jdbc:sqlite:signup.db");
//do stuff here
}
I have installed hadoop-2.3.0 and successfully configured hive on my machine ..
i have windows 7 on my machine ..
now i 've created so simple project to just connect to hive driver ..
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class Hive_java{
private static String driver = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Class.forName(driver);
Connection connect =
DriverManager.getConnection("jdbc:hive2://localhost:10000/data", "", ""); //connecting to default database
}
}
and added these jars
now i have this error which can't solve it for some days .. connection refused
please tell me what can i do as am beginner in hive .. thanks in advance
I am new to android, So i need a basic knowledge,How to connect to the database and Select some of the values from it.
These are all the following steps i have already completed by watching and reading some online tutorials.
Created a New ANDROID Project Named And2.
Created a New JAVA Project named MYSQLConnection which is used to store the database connection.
I have Downloaded mysql-connector-java-5.1.34 file Online and added it.
I have attached the Screen Shot the total overview of my eclipse.
Now i just needed to access the database in And2 and Write a Simple Select Query So that i can make sure that connection is created.
Shown below is the Java file for DB Connection.
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.Statement;
import com.mysql.jdbc.*;
//import com.mysql.jdbc.Connection;
//import com.mysql.jdbc.Statement;
public class Main {
public static void main(String[] args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
try
{
String connectionUrl = "jdbc:mysql://localhost:3306/testdatabase";
String connectionUser = "root";
String connectionPassword = "12345";
Connection conn = DriverManager.getConnection(connectionUrl, connectionUser,
connectionPassword);
//Statement stmt = conn.createStatement();
// ResultSet reset = stmt.executeQuery("select * from TableName");
//
// //Print the data to the console
// while(reset.next()){
// Log.w("Data:",reset.getString(3));
//
// }
}
catch ( SQLException err )
{
System.out.println("Database connection failed");
}
}
}
Any Help appreciated.
When I run the following code only values from the first row show
package Database.H2;
package Database.H2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class CreateTable {
public static void main (String[] args) throws ClassNotFoundException, SQLException {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/~/test", "sa", "");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM TEST");
while (rs.next()) {
System.out.println(rs.getString("NAME"));
conn.close();
}
}
}
There are 5 rows in the database that I entered manually. How can I get all the rows to display?
Any help will be greatly appreciated. Thank you.
This line is the cause:
conn.close();
In your loop rs.next(), you called conn.close, so it prints the 1st row correctly. Bring the conn.close outside your loop.
Just to add on, instead of importing all files separately sql.Connection, sql.DriverManager, sql.ResultSet, sql.SQLException and sql.Statement. Just import one file like this; import java.sql.*;