How to make an standalone java application that uses mysql driver
Hi,
I have an application that makes connection to a mysql database, on my computer, I set on classpath the driver address, so everithing works fine.
The problem is that I want to execute my application from other computers, where the classpath does not have the drivers.
So my question is how can I package the driver? so, everybody can run my application from a Jar, for example.
thanks in advance,
- Susana
Nobody answered me, but I post the solution I found, that maybe can help somebody else with this problem:
I packed all my application sources (.class) and the drivers sources (.jar) with the tool: FAT JAR. It is an Eclipse plug-in. And now I can run mi application from the resulting Jar in other machines without installing the conector.
Bye,
- Susana
Similar Messages
-
Standalone java application that calls Db2
Hi,
I am trying to use coherence in my standalone java
application that makes JDBC calls to Db2.
The sql statemet is like below:
select lastName,firstName from employee where empNo=2224;
In the application,I would read from the flat file say
200 account numbers and query the database.
If I have queried the database already with the given
account,I want to retreive from the cache.
I am having real trouble in getting this work with
coherence software.
Any psudo code in this regard will help me a lot.
Thanks
DJonHi Jon,
Thanks for the mail.I am struck in
implementing the coherence in the sample program.
any help in this regard is appreciated.
Thanks
DJon
Below is the sample program that works without coherence.go to db2 and get the information.
import java.sql.*;
import java.util.*;
public class DB2Client
static void printColumn(String in)
System.out.print(in);
System.out.print(" | ");
public static void main(String[] args)
Driver myDriver = null;
Connection myConnection = null;
try
myDriver =
(Driver)Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
myConnection =
DriverManager.getConnection("jdbc:db2:sample","dujon","jeff");
PreparedStatement myStatement
= myConnection.prepareStatement("SELECT
empno,firstnme,lastname FROM employee where empno > ?");
myStatement.setString(1,"00");
ResultSet
myResults=myStatement.executeQuery();
while (myResults.next())
printColumn(myResults.getString("empno") + "");
printColumn(myResults.getString("firstnme") + "");
printColumn(myResults.getString("lastname"));
System.out.println();
} catch (Exception e)
e.printStackTrace();
} finally
try
if (myConnection != null)
myConnection.close();
} catch (Exception e)
Now,to implement the above sample with
coherence I have written 2 programs.
1. TangosolDB2Cache.java
2. TestDB2Cache.java
import com.tangosol.net.cache.CacheStore;
import com.tangosol.util.Base;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
* An example implementation of CacheStore
* interface.
* @author erm 2003.05.01
public class TangosolDB2Cache extends
Base implements CacheStore
// ----- constructors
* Constructs DBCacheStore for a given
database table.
* @param sTableName the db table name
public TangosolJDBCCache(String
sTableName)
m_sTableName = sTableName;
configureConnection();
* Set up the DB connection.
protected void configureConnection()
try
Class.forName("com.ibm.db2.jcc.DB2Driver");
m_con =
DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
m_con.setAutoCommit(true);
catch (Exception e)
throw ensureRuntimeException(e,
"Connection failed");
// ---- accessors
* Obtain the name of the table this
CacheStore is persisting to.
* @return the name of the table this
CacheStore is persisting to
public String getTableName()
return m_sTableName;
* Obtain the connection being used to
connect to the database.
* @return the connection used to
connect to the database
public Connection getConnection()
return m_con;
// ----- CacheStore Interface
* Return the value associated with the
specified key, or null if the
* key does not have an associated
value in the underlying store.
* @param oKey key whose associated
value is to be returned
* @return the value associated with
the specified key, or
* <tt>null</tt> if no value is
available for that key
public Object load(Object oKey)
Integer iKey = (Integer)key;
return query("select
lastName,firstName from employee where empNo = " + iKey);
* Store the specified value under the
specific key in the underlying
* store. This method is intended to
support both key/value creation
* and value update for a specific key.
* @param oKey key to store the
value under
* @param oValue value to be stored
* @throws
UnsupportedOperationException if this implementation or the
* underlying store is
read-only
public void store(Object oKey, Object
oValue)
mycacheTable(oKey,oValue);
public void erase(Object oKey)
public void eraseAll(Collection
colKeys)
throw new
UnsupportedOperationException();
public Map loadAll(Collection colKeys)
throw new
UnsupportedOperationException();
public void storeAll(Map mapEntries)
throw new
UnsupportedOperationException();
// ----- data members
Hashtable mycacheTable = new Hashtable(1000);
* The connection.
protected Connection m_con;
* The db table name.
protected String m_sTableName;
* Driver class name.
private static final String DB_DRIVER =
"org.gjt.mm.mysql.Driver";
* Connection URL.
private static final String DB_URL =
"jdbc:db2:sample";
* User name.
private static final String DB_USERNAME =
"dujon";
* Password.
private static final String DB_PASSWORD =
"jeff";
TESTING THE ABOVE PROGRAM
import com.tangosol.net.cache.CacheStore;
import com.tangosol.util.Base;
import
com.tangosol.net.cache.MapCacheStore;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class TestDB2Cache {
public static void main(String args[]){
TangosolJDBCCache mycache = new
TangosolDB2Cache("employee");
Connection
con=mycache.configureConnection();
MapCacheStore cacheStuff = new
MapCacheStore(HashMap hmap);
String[] employeeNumbers =
{"000010","000020","000030","000040","000050"};
// find whether it has been cached already
for(int
i=0;i<employeeNumbers.length();i++){
oCurValue =
cacheStuff.load(employeeNumbers);
if(oCurValue == null){
// execute SQL statement
con.executeQuery(oCurKey);
else
//get from cache the values and return
cacheStuff.load(oCurKey); -
How To make un killable java application even by task manager ?
Hi,
Anybody help me how to we make un killable java application(applet).
Thanks in Advance
Mayan Alagar
[email protected]Mayan_Alagar wrote:
Anybody help me how to we make un killable java application(applet). Why do you think you need that?
Tell us what problem you are trying to solve
instead of asking how to implement how you think it should be solved. -
I need to build a LabView application .exe to run with the 2012 Runtime, for legacy support. I currently have LabView 2013 installed on my development system, and have 2014 available. How can I build an application that uses the 2012 runtime on this development system? Do I have to downgrade to 2012? Thank you.
We have existing customers that have installed our application that was originally built with 2012 (provided by a contractor that is no longer available). Due to IT regulations, it is far easier to update these customers by simply replacing the .exe file, than creating an install that their IT department must run.
If I have to downgrade to LabView 2012, where can I get the installation for this? -
How to pack a standalone Java application
Hi, all. I have a stand alone Java application which includs some classes and some properties files. Meanwhile, I'm using some libraries(in jar files) from 3rd party as library extension.
When I developed my application in the IDE, I can run it from the IDE and it works fine.
Now I want to run it out of the IDE, it always complains that is can't find the 3rd party classes. I have tried to modify the classpath to include the extension libraries but it goes no avail. What might be the problem?
And normally, how will you pack the application to submit it to the end-users? How do you include the libraries from 3rd party without end-users' awareness?
Thanks a lot!Put it in a jar, and use the classpath-setting in the jar manifest file.
Or extract the 3rdparty libraries, and put everything in a big jar.
Or provide a .bat-file and a shellscript that sets classpath temporarily. -
How to make countdowntimer in java bean to use in jsp form
i make an aplication in jsp with XHTML MP format..i have problem to maka a countdowntimer in java bean to use in the jsp form.could anyone help me with this problem
Use JHelp, downloadable from Sun. This is a quit big package, you have to read a lot before applying.
http://java.sun.com/products/jfc/tsc/articles/javahelp/index.html
enjoy
sergio -
How can I Launch a Java application that I have written using an icon
I have just finished writing a Messaging system like Ms Outlook written completey in Java. To run my application , I would normaly type: java and then the class containing the main method eg java LogonFrame.
How can I launch my application by just clicking on an icon ?.
How can I also package and install this application the way most conventional application are packaged and installed. Do we have a sort of "java Installer" ?.
Thank you.Just make a .bat file. Open notepad, type something like
@echo off
javaw -classpath %~d0%~p0 Package.MainClass %1
Now make a shortcut to this file. Rightclick the shortcut and select start in "minimized". Thats it...
Nille -
How to make table in java application?
I am using visual cafe tool for creating the GUI interface, but i don't konw how to construct a table for my game.
thank uin visual cafe there is a table icon on the swing tab. you should be able to just drag and drop it on your interface that you are creating. once on the gui you can set the properties for the table by right clicking with the mouse and choosing 'properties'. hope this helps.
-
How to communicate with a remote application that uses http post to request connection
Ok, I will try to make this simple as to avoid any
confusion.
I am trying to receive connection requests from remote applications installed on user pc's.
The application uses POST method to send the request to connect to my database, and if required update some tables.
The application is not a webpage. I have no access to the internal workings of the application nor do I have any specific information about how it sends its POST. I am sure of the following:
The app will POST to my .cfm page
"IsConnectionAllowed" = "yes"
This is asking my cfm page if its ok to connect. I would need to use a <cfif> to verify the the first part of the POST is in fact
"IsConnectionAllowed" = "yes"
If this returns true, (the app also uses to POST to pass "username" and "password") my .cfm page will then perform a query and check the username and password against the database. If a matching record is found, the application expects my page to reply with
"#Answer# OK- connected;"
Once the answer is given the application will then respond with data to insert or update my tables.
Now, I know how to do the queries and update tables etc, but I have never received data from an application before.
I tried using the <cfform> tag with a mehod of GET, and then trying to send my reply with <cfoutput>, but that didn't work. The application doesn't give any feedback or error messages. It either connects or not.
I also tried the <cfhttp> tag, but that didnt work either. I am not very experinced with coldfusion. I used it years ago and am just getting back into it.
I am sure this is a pretty easy thing to do, but my methods arent working.
Using the above information, can somone please show me how I would accomplish this communication? I can then use the same method to retrieve the data for my table updates and queries.
Here is a sample of what I have already tried:
<cfform method="get">
<cfif>
"IsConnectionAllowed" = "yes"
<!-- I need to query a username or password. But for testing I will just give the OK to connect -->
<cfoutput>#Answer# Ok - connected;</cfoutput>
<cfelse>
<!-- When I query username and password, if the query returns no records I deny the connection -->
<cfoutput>#Answer# Not connected;</cfoutput>
</cfif>
</cfform>
BTW, I have examples of this being done using .php and .asp. I need to do this using .cfm. I can post the either the .php or.asp code if it will be helpful in converting the function into a .cfm page.Thanks Fernis.
That code allowed me to connect!
I have an error on the remote application, but I think thats due to the fact that I commented out the database connection and query strings. As I am mostly concerned with connection at this point, I just wanted to test that my cfm page will recognise the POST request and send the right answer, In this case
##Answer## Ok - connected;
That worked perfectly and the application received the ok to connect.
I can now use your code as a base to carry on with my database connection and update query.
I can't thank you enough. I wouldnt have figured that out in a million years of trial and error.
I knew it was simple though. I was over thinking it.
I do have one last question though... In the code you presented you have
<cfif structKeyExists(Form,"isConnectionAllowed") AND form.isConnectionAllowed EQ "yes">
Can you you explain this structKeyExists(Form,"isConnectionAllowed")
I have never seen this before. Why the Form followed by a comma? I am guessing you are asking if there is an element in the POST called "isConnectionAllowed". Is that correct? If so, do I not need to do that for each POST'ed element such as username, password, and each of the other fields that will be updated in the session? -
How to make my N80 read websites that uses Indic U...
Is it possible to get my N80 read the websites written in Indic Unicode text... Currently I see only squares instead of the text... Also I see squares in Indic language messages.. Can I have a font that supports Indic languages?
N80 IE, E51, E71I copied some Malayalam Unicode fonts to e:\resource\fonts and yes, the squares are replaced by the Malayalam characters. There is no rendering support yet though, as my firmware is from MiddleEast.
I hope Nokia will consider adding "Uniscribe" support in the newer firmwares, just to "read" the data.
N80 IE, E51, E71 -
To support certficate based client authentication using 2-way SSL from a standalone java application which uses JNDI and JSSE1.0.2 to connect to an SSL enabled LDAP Server how do we configure the certmap.conf?Is there any additional setup required at the LDAP Server side apart from enablinf SSL with the option"Required Client Authentication" enabled.The 2 way SSL handshake goes through but the access log file (After configuring the certmap.conf for the issuer DN of the client certficate etc..)shows SSL failed to LDAP DN?But inspite of this access log error the Java client does get an SSL Connection object with which it is able to connect to the LDAP.IS the certmap.conf file being looked up by the LDAP Server at all?
have you out.flush() and out.close() before you call connection.getInputStream()?
-
How to archive a Java project that uses an Oracle XE DB?
Hi,
As the title suggests, I have a small Java application that uses Oracle XE as the database. Now that I have finished working on the application, I want to archive it and email it to friends and coworkers to test it. However, I know that none of these people have any database software installed. I also can't have them connect remotely to the one on my development machine.
Is there any way to include the database in my application archive, so that all they have to do is run the application without worrying about its back-end? Should I use another back-end?
Any help is appreciated.
ThanksUnless your database server is on a remote machine that they can connect to then you can't package the WHOLE DATABASE, software and all and send it via e-mail.
You can package your application, and also export the contents of your database into a .dmp file and send that.
The user will NEED Oracle software then to import the contents of your .dmp file. -
JAVA Application speed using JARs
Good day guys,
I have a quick question about the perfomance.
When I write Java application that uses other third party JARs, do I have to remove all the
classes from those jars that I dont use to make application run faster or it does not metter?
Thank you very muchAjaxian wrote:
Good day guys,
I have a quick question about the perfomance.
When I write Java application that uses other third party JARs, do I have to remove all the
classes from those jars that I dont use to make application run faster or it does not metter?
Thank you very muchLet's take that to another level. Suppose this is on Windows, and that none of the apps running on it will ever use some DLL(s) or some APIs in those DLLs, which are already installed on the box. Do you really think you should worry about trimming them down?
And surely none of the java specific apps you will write will use ALL of the classes and methods in the whole java library, so should you whack those too? -
How to make a Java application that will change the client box's IP address
HI how to make a Java application( that application would be run on the client ) that will change the client box's IP address ( IP address of itself )
If you can do that through the command line, then use Runtime.getRuntime().exec(...) to execute your command.
-
How to get Portal user from a standalone Java application
Hi,
I have a standalone Java application from where I need to fetch the Portal User Information like userid and email id.
I am using the below line of code
iUser = UMFactory.getUserFactory().getUserByLogonID("e017939");
I have included the jar file com.sap.security.api , But it was giving me the below exception
java.lang.NoClassDefFoundError: com/sap/tc/logging/Location
at com.sap.security.api.UMFactory.<clinit>(UMFactory.java:55)
at com.am.wcas.java.mailscheduler.kmaccess.FetchDataFromKM.getiUser(FetchDataFromKM.java:29)
at com.am.ScheduleEmails.main(ScheduleEmails.java:89)
and I am getting a pop Up message from the Java Virtual Machine Launcher, saying a Fatal Exception has occured and the Program will exit.
Then I went throught he SDN threads and they asked me to include the
logging.jar and com.sap.security.perm.api .
I Included them, then also, it is giving me Exception
java.lang.NoClassDefFoundError: com/sap/engine/lib/logging/LoggingHelper
at com.sap.security.api.UMFactory.<clinit>(UMFactory.java:56)
at com.am.FetchKMData.main(FetchKMData.java:30)
Exception in thread "main"
and I am getting a pop Up message from the Java Virtual Machine Launcher, saying a Fatal Exception has occured and the Program will exit.
Kindly let me know if it is possible to access the User info using UMFactory in a standalone Java application. If yes kindly let me know where i am going wrong.
Regards,
Shilpa B.VHi Shilpa,
1. Check that you have added com.sap.security.api within the Your Project>Libraries folder (under navigation tab) and also added jars in the build path of the Your Project under project>properties>Build Path.
2. In case you have a DC instead of Web Dynpro Project then you have to add the com.sap.security.api under Your DC>Used DCs and have compile time and runtime dependency added.
Here java.lang.NoClassDefFoundError is caused basically due to only build time dependency added and reference to the jar missing at runtime. Rest the code to retrieve the current user id using UME API and getUserByLogOnID("....") method with/without portal environment would not be an issue at all.
Regards,
Tushar SInha
Maybe you are looking for
-
Hi, I am back again with my tweaked brain. LOL I am trying to go back to Firefox 4, which I had so much less trouble with and liked a whole lot more. I am told that after installing the older version I need to turn off the automatic Firefox software
-
MY DOC PRINTS CORRECTLY BUT EMAIL COPY SHOWS ERROR " INSUFFICIENT DATA" ????
-
By- Product is Power How do we Map this
Hi Everyone I need your help in an Implementation scenario. We have a set-up where :- 1. Oil is the Raw Material .Oil is being taken as pipe -line material . 2. Carbon Black is the Finished Product.Carbon black is produced in production line.We have
-
Set Metadata for custom fields on Supplier (BUPA)
Hi, I have to add a new field to BASIC DATA view of Supplier. I have appended the field in the required structures. Now, I need to set the properties of field to make it as visible and enable. How can we set these properties? Is it through implementi
-
Hi, is the bankcard 8 fico score different from the score we get on myfico? At one time the score was the same both places now they are not. fnbo says 676, myfico says 683.