SQLite driver is not suitable - java

I'm trying to connect to database with SQLite. There is no error appears in editor, but when I run the application I am getting error message that says;
"java.sql.SQLException: No suitable driver found for jdbc:sqlite//school.sqlite"
package dbUtil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class dbConnection {
private static final String SQCONN = "jdbc:sqlite//school.sqlite";
public static Connection getConnection() throws SQLException {
try {
Class.forName("org.sqlite.JDBC");
return DriverManager.getConnection(SQCONN);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
}
I did download the latest sqlite driver to library which is "sqlite-jdbc-3.23.1"
Can anybody help me for this error message? Thankyou,

If anybody sees this post and having the same problem, I just changed
private static final String SQCONN = "jdbc:sqlite//school.sqlite";
to fullpath;
private static final String SQCONN = "jdbc:sqlite:/C:/Users/MAMI/Desktop/OKUL/SchoolSystem/src/school.sqlite";
as #a_horse_with_no_name mentioned. Works fine now.
Thanks again

Related

Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException

Here is my code:
import java.sql.Connection;
import java.sql.DriverManager;
public class TestJdbc {
public static void main(String[] args) {
String jdbcUrl = "jdbc:mysql://localhost:3306?hb_student_tracker?useSSL=false&serverTimezone=UTC";
String user = "hbstudent";
String pass = "hbstudent";
try {
System.out.println("Conectiong to database: "+jdbcUrl);
Connection myConn =
DriverManager.getConnection(jdbcUrl,user,pass);
System.out.println("Connection succesful!!!");
}
catch(Exception ex) {
ex.printStackTrace();
}
}
}
It fails with the following error:
Conectiong to database:
jdbc:mysql://localhost:3306?hbstudent?useSSL=false&serverTimezone=UTC
java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception:
com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL,
failed to parse the connection string near '?useSSL=false&serverTimezone=UTC'.
What am I doing wrong?
You better check the documentation.
Probably, the problem is in URL. It should be a slash after port and before the database name.
String jdbcUrl = "jdbc:mysql://localhost:3306/hb_student_tracker?useSSL=false&serverTimezone=UTC";

get data from postgres into a .jsp page

i guess this is a newbie question...Don't seem to find it anywhere, so i thought i asked, hope you don't get mad :) I am really new to all this jsp and java thing and try to figure out what's going on.
So, I have created 2 classes that create the connection to my postgres database. The thought was to have a class that creates the connection and use it anytime i need it, cause i will need to retrieve data many times in the future.
The first one: DbContract.java
package Database;
public class DbContract
{
public static final String HOST = "jdbc:postgresql://localhost:5432/";
public static final String DB_NAME = "DB_1";
public static final String USERNAME = "postgres";
public static final String PASSWORD = "12345";
}
and the second one: TestConnection.java
package Database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class TestConnection
{
public static void main(String[] args)
{
try
{
Class.forName("org.postgresql.Driver");
Connection c;
c = DriverManager.getConnection(
DbContract.HOST+DbContract.DB_NAME,
DbContract.USERNAME,
DbContract.PASSWORD);
System.out.println("DB connected");
}
catch (ClassNotFoundException | SQLException e)
{
e.printStackTrace();
}
}
}
Now, i want to use these, in order to retrieve data from a existing database i have (postgres and it is filled with records.), BUT from a jsp page. Is it possible?
Can anyone, help me step by step to do it, or is it too easy?
thanks in advance

Hive server not starting

Iam new to the hadoop ecosystem. Tried to access hive through jdbc. For that I have written the following code
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveConnection {
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000");
Statement stmt = con.createStatement();
ResultSet res = stmt.executeQuery("select * from test.employees");
while (res.next()) {
System.out.println(res.getString(1));
} }}
and started the hiveserver2 (hive version 0.12 & hadoop version 1.1.2) through the terminal and im getting the status as "Starting HiveServer" . When i tried executing the above code from eclipse im no getting any error and any results neither(Got the same when i executed the executable "hiveserver" ).
Can any one help me out.
Thanks in advance.
Following ways are most really reason for your problem.
1.Is the hive-jdbc-*.Jar having classpath like this "org.apache.hadoop.hive.jdbc.HiveDriver" or "org.apache.hive.jdbc.HiveDriver"?
2.While connection,you need to pass the user name and password like this?
If you use hive server2 then you have to set the connection like below.
con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "", "");
Above ways are really helpful for you.
Thanks in advance.

java database connection end up with the db:java.sql.SQLException: No suitable driver found

i am brand new to Java . Here i am trying to connect to mysql database here my code:
package Services;
package Services;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class LoginService {
private static final String USERNAME="root";
private static final String PASSWORD="";
private static final String CONNECTION_STRING="jdbc:mysql://localhost/testdb";
public void Authenticate(String uname,String password){
Connection connection=null;
Statement statement=null;
ResultSet result =null;
try{
//Class.forName("com.mysql.jdbc.Driver").newInstance();//if java 6 or higher there is no need to load cass
connection =(Connection)DriverManager.getConnection(CONNECTION_STRING,USERNAME,PASSWORD);
System.out.println("Connection to the database is established ");
}catch(SQLException e){
System.out.println("Can't connect to db:" +e );
}
}
}
This end up with an error like this:
Can't connect to db:java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/testdb
i have added the jar file and by right clicking in it added the same to build path;what wrong with my code .
You have to download the JDBC driver ..
after that ... add it to your library..
You can read this! It's really simple after you get the idea!
here is the link! http://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-connect-drivermanager.html
And this one! http://www.mkyong.com/jdbc/how-to-connect-to-mysql-with-jdbc-driver-java/
Good luck!

how to to connect and use JDBCUtil

hi
i want to use Class JDBCUtil in java language and eclips workspace and I have the below code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDBCUtil {
static final String CONN_STR = "jdbc:hsqldb:hsql://localhost/";
static {
try {
Class.forName("org.hsqldb.jdbcDriver");
} catch (ClassNotFoundException ex) {
System.err.println("Unable to load HSQL JDBC driver");
}
}
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(CONN_STR);
}
}
but when I run it, I get the below Exception:
Unable to load HSQL JDBC driver
Exception in thread "main" java.lang.NullPointerException
at domain.EnrollCtrl.getCurrentOfferings(EnrollCtrl.java:78)
at ui.UI.main(UI.java:28)
in addition there is UI and EnrollCtrl and another file in this project but the error is in this path.
how can i fix this error? should I do sth for connectin to jdbc:hsqldb:hsql://localhost/?
thank U
your String CONN_STR = "jdbc:hsqldb:hsql://localhost/"; should be
conn = DriverManager.getConnection(jdbc:hsqldb:hsql://localhost/xdb", "sa", "");
In some circumstances, you may have to use the following line to get the driver.
Class.forName("org.hsqldb.jdbcDriver").newInstance();
The chances are that you are missing the hsqldb.jar file from your classpath or some other environmental issue.
It is difficult to be certain as your question is incredibly specific to your code and environment.

Categories

Resources