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.
Related
When I call The staement
c = DriverManager.getConnection("jdbc:sqlite:sample.db");
I get a exception saying
no Suitable Driver Found for jdbc:sqlite:sample.db
The project is running in eclipse on a windows platform.
This is what I did:
WENT TO properties-> java build path -> Add external jar
added the file sqllite-3-16-1.jar
The code
try {
// exception goes off here
c = DriverManager.getConnection("jdbc:sqlite:sample.db");
} catch(Exception e){
ted=ted+1;
} //
You need to load the driver class before trying to acquire the connection. Can you try the following:
Class.forName("org.sqlite.JDBC");
This will throw NoClassDefFoundError if the driver jar is not on the classpath.
I simply want to use SQL Server database in my HTTP Servlet program but my program can't seem to connect to the database. It gives me the following error:
No suitable driver found for
jdbc:sqlserver://localhost:1433;databaseName=Bookyard;integratedSecurity=true;
This is my connection method.
package practice.bookyard.server.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Database {
public static Connection getConnection() {
String url = "jdbc:sqlserver://(LocalDb)\\MSSQLLocalDB:1433;databaseName=Bookyard;integratedSecurity=true;";
Connection connection = null;
try {
connection = DriverManager.getConnection(url);
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
}
I had the sever name as localhost:1433 earlier but I changed it to the SQL Server instance name (LocalDb)\\MSSQLLocalDB:1433 but it still seems to pick up the old name.
Also, I am not sure how to provide the right connection string when connecting to SQL Server localdb.
I am using Eclipse for Java EE, Mars 2, and I downloaded Microsoft JDBC drivers for SQL 6.0 from this website.
I ran the installation, unzipped the contents of the resulting folder. Then, I added the sqljdbc42.jar file to the build path as I am targeting JDK 1.8.
UPDATE
Upon Scary Wombat's suggestion, I have also added the path to the sqljdbc42.jar file to my classpath.
However, I still get the same error.
I am pretty confident this is a reflection issue, in that the type loader isn't able to resolve the driver type from my connection string. Which means, the connection string syntax I am using is wrong.
I changed my connection string to read as follows:
String url = "jdbc:sqlserver://localhost:1433;
instance=(LocalDb)\\MSSQLLocalDB;
databaseName=Bookyard;integratedSecurity=true;";
However, I still not only get the same error but the exception message I receive still has my old connection string. So, clearly, there's also some caching going on, I just don't know where. Who is caching my connection string and how do I refresh / clear that cache?
Could you please tell me how to provide a SQL Server instance name if I am connecting to localdb and not on the main SQL Server instance?
As #ScaryWombat and #JozefChocholacek had hinted, it turned out to be a class path issue. Apparently, you have to copy and paste just the sqljdbc42.jar file, and this file only directly into the WEB-INF\lib folder and not within any sub-folder.
I did that it still gave me that error.
That was because the WEB-INF folder structure, when I viewed it in the Project Explorer, still had the old folder structure. So, I right-clicked on the WEB-INF folder in the Project Explorer and selected the Refresh command.
I also updated my environmental variable CLASSPATH to point it to the WEB-INF folder and that error went away.
you can do like below
String url = "jdbc:sqlserver://YOUR PC NAME;instanceName=SQLEXPRESS;DatabaseName=dbname;integratedSecurity=true";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection myCon = DriverManager.getConnection(url);
note :however its not necceaary for new version of jdbc driver to load driver class manually using class.forname
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.
I'm really looking at a mystery here. I created a Java program in Eclipse and established a JDBC connection. The code is the following:
import java.sql.*;
public class Login {
public static void main(String[] args) {
try {
// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection connection = DriverManager
.getConnection("jdbc:sqlserver://localhost;databaseName=testdb; integratedSecurity=true;");
//adding port 1433 doesn't make a difference
System.out.println("Connection successful");
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select * from testtable");
while (rs.next()) {
line = rs.getString(2);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
When I'm running it within eclipse, everything's fine. The database and tables are good, library and authentication in the Java Built Path are set and I get the result I want, namely "Hello World", which is a string in the selected table.
But creating an executable JAR file and running it throws the exception "This driver is not configured for integrated authentication". It does not even connect, so even if there was an error in the database it wouldn't matter at this point.
Even more confusing is the fact, that some weeks earlier, I also created an executable JAR file and it worked!
OS: Windows Vista Home Premium x86
JDBC driver location: "C:\sqljdbc_4.0\enu\sqljdbc4.jar"
Native library location: "C:\sqljdbc_4.0\enu\auth\x86"
Java version: Java 7 Update 17 and JDK 7 Update 17
Previousely, I used Update 21, but I changed back to check if the driver could be the reason.
So, any suggestions? I'd be very grateful!
Check the runtime classpath of eclipse, then try to create a system level "CLASSPATH" variable and add the same path. Once the variable is set, execute it in new command prompt or reload the environment variables
Make sure your executable jar has the dependency in MANIFEST.MF for all the necessary jars (along with MainClass)
Finally, It is always a practice in Java to make the first alphabet in Capital ("Login" instead of "login")
Actual problem is that if you run your project from eclipse, it will automatically add run arguments that are defined in run/run config//arguments, so you run your program with properly set path to sqljdbc_auth.dll. But if you export your application to .jar file and just run it, you will get these errors cause there is no correct classpath to auth file.
So, if you run your app from command line with proper arguments, it should be working.
how to connect mysql database to desktop java application using jdbc ?
the environment is ubuntu 12.04 Lts i tried so many ways but all of them throw an exception on executing
Class.forName("com.mysql.jdbc.Driver");
the exception say :
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
the full code is :
import java.sql.*;
public class CRUDForGoods {
private Connection connection ;
public Vector<GoodsStore> goods ;
public CRUDForGoods(){
try{
DriverManager.registerDriver(new JdbcOdbcDriver());
connection = DriverManager.getConnection("jdbc:odbc:dbName","root", "root");
}
catch(Exception ex) {
System.out.println("##connection");
ex.printStackTrace();
}
}
com.mysql.jdbc.Driver not found while executing the code.
You need mysql connector to get it run (the jar includes com.mysql.jdbc.Driver). You can find it here
Download and include the jar file in your classpath.