Iam new on using NetBeans 7.4 , i want to connect my java application to MYSQL , the application is desktop application .
i have already install MYSQL workbench 5.2 and create database with one table .
from NetBeans services on Databases i register MYSQL server , i enter these values :
localhost : 127.0.0.1 , user : root and password : root.
NetBeans ask me to set MYSQL command Path (Path to start command) i insert this path :
C:\Program Files\MySQL\Connector ODBC 5.1\myodbc-installer.exe
from main class in java i saw from net how to set connection :
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/sameer", "root","root");
System.out.println("Connected database successfully...");
} catch (Exception e) {
System.out.println(e);
}
but all time the exception will execute :
java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1:3306/sameer
You need to include the mysql connector jar in your project.
If you haven't downloaded it yet you can find it here http://dev.mysql.com/downloads/connector/j/
Once you have downloaded it:
right click on the project
select Properties
select Libraries -> Add JAR/Folder
navigate your file system to select the jar you previously downloaded
save and it will run correctly
Related
So I am trying to add new connection to my Netbeans' database which is MySQL but I am getting Big Integer casting error can someone please help me?
In detail:
I right click on existing MySQL Server at localhost:3306 [root(disconnected) >> select connect and this pops up
Unable to connect to the MySQL server:
org.netbeans.api.db.explorer.DatabaseException: org.netbeans.api.db.explorer.DatabaseException: java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long.
The server may not be running or your MySQL connection properties may not be set correctly. Do you want to edit your MySQL connection properties?
And my basic and admin properties are OK.
And I tried this too: Right click on databases >> select New Connection >> Driver: MySQL(Connector/J driver), JDBC URL: jdbc:mysql://localhost:3306/mysql , but when I test the connection it gives me the same error.
**MySQL server is running.
Thank you.
This is a JDBC Driver problem
I had a similar problem in netbeans. I resolved by removing the default driver (Connector/J driver) from the driver list under databases/drivers as shown below.
This happened with jdbc v8.0.12 on mysql v8.0
So after removing the default jdbc driver, I add an old version of the driver mysql-connector-java-5.1.47.
The connection the succeeded.
What is the version of your MySQL driver and your MySQL? If you want to use MySQL 8, for example, you could try to use a MySQL driver which supports MySQL 8.
Try updating your mysql driver.
To install the driver:
1° Go to the services tab, just after databases.
2° Right click on the drivers folder and select add new driver.
3° Click add and look for the .jar of the driver you downloaded.
Remove and clean the jdbc connector jar files already come with netbeans.
Add a new connector jar file to the jdbc library.
(You can download ==> mysql-connector-java/8.0.11
Try again, connection is going to be ok now.
I had developed a Java Application Project using Netbeans IDE 8.2 on Ubuntu14. How can I have its installers for Linux Systems using Netbeans IDE(.deb) Native Packaging.
I had packaged it by following instruction in this link
But, this tutorial above mentioned is NetBeans 7.4 native packaging in Windows. But I followed this tutorial in Netbeans8.2 in Ubuntu(my system). And I got .deb file in specified folder in the tutorial mentioned above.
The Project-name-1.0.deb file could be successfully installed in my Ubuntu System, but while running this installed application it shows error: "java.sql.SQLException: Opening db:'DB-NAME.sqlite' : Permission denied"
My project uses sqlite DB for data storage. I had used JAR sqlite-JDBC-3.19.3.jar for its Library.
I had used Netbeans IDE 8.2 in Ubuntu and created the new Java Application Project in it.
Now, how can I package this Java Application project to get its installer for Linux(.deb) without this Permission denied error
The java Connect.java class is as follows
import java.sql.*;
import javax.swing.JOptionPane;
public class Connect {
Connection con = null;
Statement stmt = null;
public static Statement ConnectDB() {
try {
Connection conn = null;
Statement stmt = null;
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:JavaApp3DB.sqlite");
stmt = conn.createStatement();
return stmt;
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
return null;
}
}
The application execute successfully in NetBeans without any permission denied error. But, it shows the error when the Packaged (.deb) installer when installed and executed in Ubuntu.
Change this jdbc:sqlite:JavaApp3DB.sqlite
to this jdbc:sqlite:JavaApp3DB.db
When you want to connect to your database you need an address and this address mention to a file we call database.db not .sqlite.
This question already has answers here:
Connect Java to a MySQL database
(14 answers)
Closed 6 years ago.
I am a newbie to J2EE.I have checked similar questions but nothing helped.
I am creating a simple login application but i am facing the above error.
I have mysqlconnector in build path and a lib folder as shown in the image :SQL connector
The source code of the application is as follows:
LoginDao.java
This file connects the application to mysql database.
String userName = "root";
String password = "mysql";
I have provided the username and password of mysql here.Is this correct?
For this I have created a database in mysql:
create database form;
use form;
create table login(username varchar(20),pass varchar(20));
show tables;
insert into login values("nehal",12345);
Now the project runs properly but when i enter username as nehal and password:12345, it gives the above error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
1 way =>Paste the mysqlconnector.jar file in jre/lib/ext folder.
2 way => set classpath
open comman prompt and write:- C:>set classpath=c:\folder\mysql-connector-java-5.0.8-bin.jar;.;
in IDE :
Right Click the
project -- > build path -- > configure build path
In Libraries Tab press Add External Jar and Select your jar.
Don't know eclipse that much but i would guess that your library is mussing at runtime. As i see you use apache tomcat and it seems that it doesn't has that mysql jar.
You have to add that jar to your apache tomcat. See Where do I have to place the JDBC driver for Tomcat's connection pool?
Iam trying to connect my app to the MySQL Back on my OpenShift Account via jdbc. Here my source:
Class.forName("com.mysql.jdbc.Driver");
Connection m_connection = DriverManager.getConnection(url , user , pass);
i´ve added my jdbc_connector.jar to the build path, but if im testing it on localhost or in web i always get an
'java.lang.ClassNotFoundException: com.mysql.jdbc.Driver'
How to solve the problem, where to add the jdbc_connector.jar?
Thanks.
JBDC need you to have a path to the jar for the server you are using in path...
Soooo...
Do not forget to add the path of the connector to the classpath. If the connector name is
mysql-connector-java-5.1.21-bin.jar stored in C:\mysql-connector-java-5.1.21, then
add c:\ mysql-connector-java-5.1.21\mysql-connector-java-5.1.21-bin.jar to the
classpath.
Oh and here is the connector http://dev.mysql.com/downloads/connector/j/
I want connect my MS access file with Java GUI program,but I have problem with connection....
I have Windows 7 64b, and ms office 2007.
When I opened the ODBC driver manager in the control panel I havent found any driver for Microsoft Access (maybe when I started the ODBC is started running the 64bit ODBC, now I think is running the 32bit ODBC.
I read this and I make it :
"jdbc-odbc connection for window 7 64 bit machine..
1 . Right click Data source (ODBC)..go to properties change the folloing thing
target [ %SystemRoot%\SysWOW64\odbcad32.exe ]
start in : [ %SystemRoot%\System32 ]
press enter and continue as admin source: source link
"
) Now when I start in conctrol pannel the ODBC I can see the driver screenshoot
My program code(I tried two ways but I have same error):
public void Connect() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// String DatabaseFile = "D:java/Invertory.mdb";
// String DATABASE =
// "jdbc:odbc:Driver="
// + "{Microsoft Access Driver (*.mdb, *.accdb)};"
// + "DBQ=" + DatabaseFile;`enter code here`
String DATABASE ="jdbc:odbc:Driver= Microsoft Access Driver (*.mdb, *.accdb);DBQ=Invertory.mdb";
CONEX = DriverManager.getConnection(DATABASE);
} catch (Exception X) {
X.printStackTrace();
//JOptionPane.showMessageDialog(null,e);
}
}
error
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Use UCanAccess JDBC Driver :
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://<mdb or accdb file path>",user, password);
for example:
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://c:/pippo.mdb");
So for your example it will be Connection conn=DriverManager.getConnection("jdbc:ucanaccess://"+path)
If you are using Windows 64-bit you probably need to go to this path
C:/Windows/SysWOW64/odbcad32.exe
Then I noticed that you are using the direct path instead creating new System DSN, your direct path is correct till the path to the access file you must give the full path like this :
jdbc:odbc:Driver= Microsoft Access Driver (*.mdb, *.accdb);DBQ=path/to/Invertory.mdb"
To get the path you probably need to use java.io.File that have a method returns the abslute path to the file see the example :
import java.sql.*;
public class TestConnection {
Connection con ;
Statement st ;
ResultSet rs ;
String db;
public TestConnection (){
try{
String path = new java.io.File("Invertory.mdb").getAbsolutePath();
db ="JDBC:ODBC:Driver=Microsoft Access Driver (*.mdb, *.accdb); DBQ="+path;
doConnection();
} catch(NullPointerException ex){
ex.printStackTrace();
}
}
public void doConnection(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(db);
st = con.createStatement();
rs = st.executeQuery("select * from Invertory");
while(rs.next()){
System.out.println(rs.getObject(1));
}
}catch(SQLException | ClassNotFoundException ex){
System.out.println(ex.toString());
}
}
public static void main(String...argS){
new TestConnection();
}
}
I answered a similar question enter link description here a while back.
Basically at that time:
You could connect to Ms-Access from 32 bit java through the JDBC-ODBC bridge
You could not connect to a 32 bit Odbc driver through the JDBC-ODBC from 64 bit java. There was a message telling you that you can only connect from a 32 bit programs
While Microsoft does provide a 64 bit Ms-Access driver, it did not work with Java's 64 bit JDBC-ODBC driver.
Since then there seems to be a new open-source Ms-Access JDBC Driver Ms-Access JDBC driver. I have no Idea how good it is.
You just missing something in your code right here :
db ="JDBC:ODBC:Driver=Microsoft Access Driver (*.mdb, *.accdb); DBQ="+path;
You need to add {} between Driver= and )=; .
Like this Below
db ="JDBC:ODBC:Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ="+path;
final String fileName = "c:/myDataBase.mdb"
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+fileName;
Connection con = DriverManager.getConnection(url,username,password);
The problem is that you should run on Java 32 bit try to install latest JDK and it will work
I run it using JDK version "jdk-7u67-windows-i586.exe"
On a 64 bit system, you should:
run as admin accessdatabaseengine_64.exe
run java - 7-64 bit - jre.
if you are working in NETBEANS then after unzipping ucanacess.zip file add all jar file in the classpath using property window of project click on compile tab and add jar file then compile and test app.
JDBC-ODBC MS-ACCESS CONNECTION STOPPED WORKING IN JDK8. I solved the issue by installing JDK7 along with JDK8 in the same PC, once installed JDK7 I assigned it as the JDK version to use in my project as follows in Netbeans:
1.RIGHT CLICK THE PROJECT IN THE LIST > CLICK PROPERTIES
2.CLICK LIBRARIES ON THE LEFT NAVIGATION TREE
3.CLICK BUTTON MANAGE PLATFORMS > CLICK BUTTON ADD PLATFORM...
4.FOLLOW WIZARD, DESPITE IT SHOWS JAVA STANDARD EDITION CLICK NEXT
5.NAVIGATE TO C:\Program Files (x86)\Java AND SELECT THE FOLDER OF JDK7 > CLICK NEXT
6.THE FIELD AUTOFILL WITH THE RIGHT INFO... > THEN CLICK FINISH
7.SELECT THE JDK PLATFORM FROM THE LIST > CLICK CLOSE > OK
8.JDK7 SHOULD SHOW IN LIBRARIES PACKAGE.
JDK7 in Libraries Package
Click Back in Browser to return here after looking at the image...
From here on everything must run smoothly.
Hope it solves your problem.
Thanks.