I'm currently looking to write an importer in my Java program to import data from a file which contains a JET database, but so far searching for a JDBC driver for this format (or just another Java library which can read from it) has proved fruitless.
Does anyone know if such a driver exists, or if not what (platform independent) alternatives might be available?
I actually have been importing CSV files into Access database using JDBC and jetEngine query like this
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "C:/Automation_Tools/Databases/Data.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= fileName.trim() + ";DriverID=22;READONLY=false}";
// add on to the end now we can get the connection from the DriverManager
con = DriverManager.getConnection( database ,"","");
and then using query like this
String sql = "INSERT INTO " + accessTableName + " SELECT * FROM [Text;HDR=YES;TextDelimiter=\";Has Quotes=TrueFMT=Delimited(,);DATABASE=" + csvDirPath + ";].[" + csvFileName + "]";
//Import/create table
String sql = "SELECT * INTO " + accessTableName + " FROM [Text;HDR=YES;TextDelimiter=\";FMT=Delimited(,);DATABASE=" + csvDirPath + ";].[" + csvFileName + "]";
`
I am just now researching this myself and am going to try out UCanAccess. According to the main page it says that it is
an open source Java JDBC Driver implementation which allows Java developers and jdbc client programs (e.g., DBeaver, NetBeans, SQLeo, Open Office Base, Libre Office Base, Squirrell) to read/write Microsoft Access database.
Because it is a pure java implementation it run in both Windows and non-Windows Operative Systems(e.g., linux/unix). No ODBC needed.
You can use the built in JDBC ODBC bridge driver.
Use a connection string like: jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=database.mdb.
This is not platform independend. The Jet engine (or ACE) has to be installed. Sometimes there are problems with encoding and Memo fields.
There is an alternative: http://www.hxtt.com/access.html
They claim platform independence but I didn't try it myself.
Related
Does anyone know whether it is possible to execute spatialite functions on sqlite-databases in intellij?
Reference of spatialite functions: http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.2.0.html
In particular, I would be interested in using functions on type Point.
Thanks!
Edit: Functions do work within the official spatialite-gui, however I don't think there is a way to use the spatialite-gui programmatically, is there?
Here is what I tried so far: In intellij I connected the Java JDBC library and tried using function ST_X(point) and ST_Y(point) with no success:
Connection c = null;
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:" + path + databaseName);
c.setAutoCommit(false);
System.out.println("Opened database \"" + databaseName + "\" successfully");
String sql = "SELECT id, ST_Y(point), ST_X(point) from tablename;";
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while ( rs.next() ) {
String msg = "Id: ";
msg += rs.getInt(1);
msg += " , Latitude: ";
msg += rs.getDouble(2);
msg += " , Longitude: ";
msg += rs.getDouble(3);
System.out.println(msg);
}
rs.close();
stmt.close();
c.close();
This throws the following exception:
Exception in thread "main" java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such function: ST_Y)
at org.sqlite.core.DB.newSQLException(DB.java:890)
at org.sqlite.core.DB.newSQLException(DB.java:901)
at org.sqlite.core.DB.throwex(DB.java:868)
at org.sqlite.core.NativeDB.prepare(Native Method)
at org.sqlite.core.DB.prepare(DB.java:211)
at org.sqlite.jdbc3.JDBC3Statement.executeQuery(JDBC3Statement.java:81)
at com.company.Test.main(Test.java:77)
Edit 2:
I'm lost. It seems that I need to load extensions to make it work. Is this not included in the JDBC connector? (I pulled the JDBC connector through Maven.)
Where do I find the correct extensions?
Are those the ones? https://www.gaia-gis.it/fossil/libspatialite/index
Or those? http://www.gaia-gis.it/gaia-sins/index.html
How do I use them? Has anybody done this before?
Before performing spatial queries you need to load the spatialite module doing
SELECT load_extension('mod_spatialite');
You can find the documentation here: Dynamically loading SpatiaLite as an extension module.
Note that the module to load must be on the system path (documentation) and the path separator must be /. Also take into account that the spatialite module and Java must be compatibles (both 32 or 64 bits).
Running Netcool 7.3.1. Looking for simple api to access Object Server Tables. I've already done the run an SQL command from nco_sql, and scraped the output into a C# data table, but wondering if there was some type of api that I could use for either C# or Java to access table data?
If you can use a more up-to-date version of Omnibus, you can use the built-in HTTP / REST API.
http://www-01.ibm.com/support/knowledgecenter/SSSHTQ_8.1.0/com.ibm.netcool_OMNIbus.doc_8.1.0/omnibus/wip/api/concept/omn_api_http_overview.html?lang=en
You may need to use sybase database adapter so far I have used below three ways to query netcool object server:
Free TDS - This is free sybase client.
Jconn3 - this is paid sybase client, but if you are using WebGUI/Impact, this driver comes with TIP.
nco_sql - here you may need to create a file with query and then pass it to nco_sql. This require extra effort to parse column wise information as output will be on console.
I prefer jconn3, simple and similar to jdbc driver, you only need this jar in classpath.
You can write your own java program to connect to Objectserver by simply initiating
//Load Sybase Driver
Class.forName("com.sybase.jdbc3.jdbc.SybDriver");
String url = "jdbc:sybase:Tds:" + host + ":" + port;
con = DriverManager.getConnection(url, user, pass);
Execute Statements
Statement stat = conn.createStatement();
ResultSet result = stat.executeQuery("Select count(*) from alerts.status");;`
My project requirement is to develop a website which interacts with a mysql database and a java application which continuously runs on the server. user is on some remote computer he sends a request to the java application by executing a jsp code on the server, the jsp code waits for the application to send the information back. once the jsp recives the info. it sends a request to database. The is a special type of database built just because of limitations of a database and my project requirements. Please tell me how the request are sent i.e. what part of java will help me do this.
some link that have the same info but not exact Communication between two separate Java desktop applications.
EDIT: my question is.... what should i use in a jsp page such that i will be able to get info. from the application which stores data in a special form of datastructure. For now I dont want to talk to database. I just want to interact with a running application.
for example there is a program on the server which returns sum of two numbers which waits for someone to give it input. now my jsp sends two numbers to the application which adds the two numbers and gives back the sum to the jsp page. now jsp page code can do anything which is not my concern for now.
Database access through the Website is one of the essential components for any web-based development. JDBC, a mechanism that allows Java to talk to databases.
Java Database Connectivity (JDBC) is a standard Application Programming Interface (API) that is used to access databases, irrespective of the application driver and database product. In other words, JDBC presents a uniform interface to databases, however, if you change the database management system and your applications, you only need to change their driver. JDBC provides cross-DBMS connectivity to a wide range of SQL databases, and other tabular data sources, such as spreadsheets or flat files.
Here is the sample example:
import java.sql.*;
class DBQuery1{
public static void main(String args[]) throws SQLException
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e){};
Connection cnn;
Statement mystmt;
ResultSet myrs;
String op = "jdbc:odbc:JavaTest";
cnn = DriverManager.getConnection(op,
"Admin", "");
mystmt = cnn.createStatement();
String sql;
sql = "SELECT * FROM SupplierMaster " +
"WHERE SupplierCode IN ( " +
"SELECT SCode " +
"FROM Relation " +
"WHERE PCode IN ( " +
"SELECT ProductCode " +
"FROM ProductMaster " +
"WHERE ProdCatg IN ( " +
"SELECT CatgID " +
"FROM CategoryMaster " +
"WHERE CategoryName = 'Eatables')))";
myrs = mystmt.executeQuery(sql);
System.out.println(" "+"Sup Code" + " " +"Sup Name" + " " + "Sup Address ");
System.out.println("--------------------------------------------------------------------");
String name, add;
int code;
while (myrs.next())
{
code = myrs.getInt("SupplierCode");
name = myrs.getString("SupplierName");
add = myrs.getString("SupplierAddress");
System.out.println(" " + code +" " + name+" " + add);
}
}
}
More information you can find on this link:
http://webserver.ignou.ac.in/virtualcampus/adit/course/cst302/block2/cst302-bl2-u3.htm
Java applications most often communicate with a relational database through the use of a JDBC driver. The driver tells the application how to communicate with a specific database. Each database vendor often provides a driver for their particular database. In your case you will need the MySql Connecter/J driver, which you will include within your project as a jar file.
The JDBC drivers provided by database vendors implement an interface so connecting to different databases is pretty much the same except for a few syntax differences between parameters. There is a ton of information that can be found about how to connect to a database through a Java application.
I am trying to connect to MS Access database from my Java application. This is my code:
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "UserInformation.accdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");
Statement st= con.createStatement();
int i=st.executeUpdate("insert into Users(User_Name,User_Password) values('"+username+"','"+password+"')");
System.out.println("Row is added");
}catch (Exception e) {
System.out.println("Error: " + e);
}
I get this exception: Data Source Name Not Found And No Default Driver Specified (ODBC)?
How can I fix it?
Thanks in advance
It can be several things. I encountered this problem in hacking a database from a 32-bit machine on my 64-bit desktop.
If you google issues using odbc with 32 vs 64 bit in Java you will see a good amount of material. What ultimately worked for me was switching from Java 5 to 6 and making sure my Eclipse runtime configurations were not setting an incompatible bit-mode.
Sorry for being a bit vague, but after spending a few hours trying to figure out I believe it can be very situational dependent.
I'm trying to get insert ID while after inserting some data in my database.
String sql = "INSERT INTO ADI.DUMMY(dummy_data) VALUES('from database logger')";
PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
int extUptReturn = ps.executeUpdate(sql);
But I got this exception:
Java exception: ''java.lang.UnsupportedOperationException'';
thrown from class name: ''sun.jdbc.odbc.JdbcOdbcConnection'', method name: ''prepareStatement'', file: ''JdbcOdbcConnection.java'', line: '1762'
The ODBC bridge driver doesn't support it. Nothing to do against. Either replace the driver or live with it. I would just use a real JDBC driver instead of the poorly-developed, feature-lacking, bug-rich Sun ODBC bridge driver. Almost all self-respected server based RDBMS vendors provides a fullworthy JDBC driver for download at their homepage. Just Google "[vendorname] jdbc driver download" to find it. Here's an overview:
MySQL JDBC driver
PostgreSQL JDBC driver (note: older versions didn't support generated keys as well).
Oracle JDBC driver (note: older versions didn't support generated keys as well).
MSSQL JDBC driver (or performancewise better, the jTDS JDBC driver)
DB2 JDBC driver is hard to find in IBM's online forest, but it's usually already included in the /java folder of the DB2 installation.
UCanAccess driver for Microsoft Access databases (more details here).
MAy be the JDBC implementation could not be supporting the sepcific opration.
CHeck the JDBC driver used.
Try this example instead of Statement.RETURN_GENERATED_KEYS:
String[] returnId = { "BATCHID" };
String sql = "INSERT INTO BATCH (BATCHNAME) VALUES ('aaaaaaa')";
PreparedStatement statement = connection
.prepareStatement(sql, returnId);
int affectedRows = statement.executeUpdate();
if (affectedRows == 0) {
throw new SQLException("Creating user failed, no rows affected.");
}
try (ResultSet rs = statement.getGeneratedKeys()) {
if (rs.next()) {
System.out.println(rs.getInt(1));
}
rs.close();
}
Where BRANCHID is the auto generated id