unusual No suitable driver found for jdbc://localhost:1527/society - java

previously i using this code to connect my database there is non error occur.
but comes to this DA files, its unable to connect to database.
i had go through most of the post but some of it i don't understand.[i'm just new to java]
i had try to use jdbc:derby://localhost:1527/societydb;create=true
but the same error occur again.
here's the code and <<< is the line the error point to.
private String host = "jdbc:derby://localhost:1527/societydb";
private String user = "nbuser";
private String password = "nbuser";
private String tableName = "MEMBER";
private void createConnection() {
try {
conn = DriverManager.getConnection(host, user, password);
System.out.println("*** Successfully established the connection to database. ***");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error Message", JOptionPane.ERROR_MESSAGE);
}
}
public ArrayList<Member> getMember() {
ArrayList<Member> memArray = new ArrayList<>();
try {
stmt = conn.prepareStatement("SELECT * FROM " + tableName);//<<< error pointing to here
ResultSet rs = stmt.executeQuery();
while (rs.next()){
Member m = new Member(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getInt(9), rs.getString(10), rs.getString(11));
memArray.add(m);}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error Message", JOptionPane.ERROR_MESSAGE);
}
return memArray;
}

From Java documentation the drivers you need are org.apache.derby.jdbc.EmbeddedDriver and org.apache.derby.jdbc.ClientDriver.
Also it clearly states
Any JDBC 4.0 drivers that are found in your class path are automatically loaded.(However,
you must manually load any drivers prior to JDBC 4.0 with the method Class.forName.)
Note : JDBC 4.0 comes as a default package from Java 7 onwards.
As for your problem search for the classes mentioned above in your class path(Ctrl + N in Intellij Idea or Ctrl + R in Eclipse). If these classes are not present google them, download and add the jar files to your class path.

Just add these external jars:
derby.jar
derbyclient.jar
How to do it:
right click your project > Properties > Java Build Path > Libraries
click 'Add external jar'
go to C:\Program Files\Java\jdk1.8.0_65\db\lib
add the derby.jar and derbyclient.jar

Related

I have problems with the connection of my embedded derby database, What's the problem?

I was making this java application, it works fine in Netbeans but when I tried to use the .jar out of Netbeans the app doesn't load the db. I'm using the derby.jar to make the db. Also the main problem it's the connection class in the public Connection CargarDB()
I'm tried changing my URL and surrounding all the block with a Try...Catch and it's not working yet.
public Connection CargarDB(){
Connection con;
String barra = File.separator;
String prjt = System.getProperty("user.dir") + barra + "Registros";
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
String db = "jdbc:derby:" + prjt;
con = DriverManager.getConnection(db);
System.out.println("Base de datos cargada");
return con;
} catch (ClassNotFoundException | SQLException ex) {
System.out.println("Error " + ex);
}
return null;
}
It doesn't give an error in Netbeans but in the derby document in the dist folder show me this:
-java.sql.SQLException: Database 'C:\Users\huevo\Documents\JAVA\Proyecto_T\dist\Registros' not found.
-Caused by: ERROR XJ004: Database 'C:\Users\huevo\Documents\JAVA\Proyecto_T\dist\Registros' not found.
I expect the output of my db show me the results in my JTable but it doesn't show anything

Getting "Unauthorized" exception when trying to create connection in Arango database using Java

I am trying to create a connection in Arango databse using Java , IDE- Eclipse but while executing the program I am getting the exception "Unauthorized".
Note: I have logged in to Arango Database with user :root
URL- http://127.0.0.1:8529/_db/_system/_admin/aardvark/index.html#logs
Program in Eclipse
import static com.arangodb.*;
public class FirstProject {
public static void main(String[] args) {
ArangoConfigure configure = new ArangoConfigure();
configure.init();
ArangoDriver arangoDriver = new ArangoDriver(configure);
String dbName = "mydb";
try {
arangoDriver.createDatabase(dbName);
System.out.println("Database created: " + dbName);
} catch (Exception e) {
System.out.println("Failed to create database " + dbName + "; " + e.getMessage());
}
}
}
I have used the tutorial https://www.arangodb.com/tutorials/tutorial-java-old/ to write this program and followed all the steps mentioned. Still getting unauthorized exception:
Failed to create database mydb; Unauthorized
You have to set the user and password (default user "root", password empty):
ArangoConfigure configure = new ArangoConfigure();
configure.init();
configure.setUser("root");
configure.setPassword("");
ArangoDriver arangoDriver = new ArangoDriver(configure);
In addition I highly suggest you to update to the new java driver (version 4.1.12). Which comes with a new API and a better performance). There is also a tutorial for it (see here).
The required code for your problem in this version would be:
ArangoDB arangoDB = ArangoDB.Builder().user("root").password("").build();

JDBC JAVA No suitable driver found for jdbc:mysql://localhost:3306/voting

Hello im trying to connect to a mysql database using JDBC my code is below.I get an error as such No suitable driver found.Searching around I found that the usual error is syntax or missing the jar file from the class path.I tried both of these solutions and dont know what to do next it wont connect.Also to manage the databases I have WAMP and mySQL workbench installed not sure if its related.
package test.jdbc;
import java.sql.*;
public class jdbctester {
public static void main(String[] args)
{
try
{
Connection myconn=DriverManager.getConnection("jdbc:mysql://localhost:3306/voting","root","Vanquish123");
Statement myStmt=myconn.createStatement();
ResultSet myRs=myStmt.executeQuery("select * from electoral");
/*
while(myRs.next())
{
System.out.println(myRs.getString("state")+","+myRs.getString("perDem"));
}
*/
}
catch(Exception exc)
{
exc.printStackTrace();
}
}
}
Try this:
Class.forName("fully qualified driver class name");
Java Class.forName, JDBC connection loading driver
this post states that you should not need it but it will not hurt you to try.
you have to add "com.mysql.jdbc_5.1.5.jar" in to your project build path... go to project property>build Path> library> add external jar and add jar file.
Connection conn = null;
try {
// Register JDBC driver
Class.forName(DRIVER).newInstance();
// Open a connection
conn = DriverManager.getConnection(Local_URL + , USERNAME, PASSWORD);
System.out.println("Connected Database Successfully...\n\n");
} catch (Exception se) {
throw new AppException("Failed to create Local Database connection", se);
}
return conn;

Source not found in debugging mode

import java.sql.*;
public class DBTesting {
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
try
{
String user = "sa";
String pass = "xxx";
String jdbcURL = "jdbc:odbc:btrsDSN";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("Driver Loaded !");
Connection conn = DriverManager.getConnection(jdbcURL,user,pass);
System.out.println("Connection Obtained");
Statement stmt = conn.createStatement();
stmt.close();
conn.close();
}
catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Error occurs in this line when the debugger tries to debug the
Connection conn = DriverManager.getConnection(jdbcURL,user,pass); . It shows source not found. I edit source lookup path but the problem still here. I also try many solutions from internet but none of them solve the problem. For convenience I also attached screen shots.
Snapshot in regular mode
Snapshot in Debugging mode
click on "edit source Lookup path" and specify the path where that particular file exists, then you will be available to see the java lines of code.
if the java file is in different project and your current project is accessing the class through jar file ,then configure your current project to work with "project dependency" instead of "jar dependency"
Hope this helps!
Good luck!

UCanAccess error: user lacks privilege or object not found

I am trying to manipulate a MS Access database with java without ODBC and I've tried following the instructions over at Manipulating an Access database from Java without ODBC but I keep on getting the error:
Error connecting net.ucanaccess.jdbc.UcanaccessSQLException: user lacks privilege or object not found: EMPLOYEE
I have already added the necessary JAR files to the library so I believe that something is wrong with my code or database. I am fairly new to databases and running Java SE 8 and using the NetBeans IDE 8.0.
The code is below
package javaapplication1;
import java.sql.*;
public class Dbase {
public static void main(String[] args) {
try {
Connection c = DriverManager.getConnection(
"jdbc:ucanaccess://C:/Users/nevik/Desktop/databaseJava/Employee.accdb");
Statement s = c.createStatement();
ResultSet resSet = s.executeQuery("SELECT [FNAME] FROM [Employee]");
while (resSet.next()) {
System.out.println(resSet.getString(1));
}
}
catch (SQLException sqle) {
System.err.println("Error connecting " + sqle);
}
}
}

Categories

Resources