Bypass the Visual Studio IDE and build a C++ DLL on the command line using cl.exe. This should generate a small lib (myoutput.lib) that you can link to when you wish to include your dll in a build.
cl -o myoutput.dll myfile1.cpp myfile2.cpp /I D:\required1\include /I D:\required2\include\win32 /link /DLL
gemette
For a more in-depth tutorial on building DLLs and then calling them via implict and explicit (GetProcAddress) calls please visit Complete Windows C++ DLL Example
Programming tutorials, examples and code snippets. C++, Java, Perl, PHP and javascript. Enterprise examples using javaEE, JNDI and Beans. Core tutorials using sockets, threads, database, IPC, XML etc. Web 2 widgets using javascrpt. Simple easy to understand step by step tutorials,
Little Gems - Very Short Helpful Hints
Here are some super short yet extrememly helpful hints that will come in handy. They cover everything from C++ to Java to Oracle and Linux. Really short but super sweet.
View all the gems
or view them individually
SQL Server Connection String
Patching with RCS
Soap Acronyms
Build dll on command line using VC++
SQL to show free space in all tablespaces in Oracle
JSP Page that displays all the HTTP headers and request parameters
View all the gems
or view them individually
SQL Server Connection String
Patching with RCS
Soap Acronyms
Build dll on command line using VC++
SQL to show free space in all tablespaces in Oracle
JSP Page that displays all the HTTP headers and request parameters
Java Native Interface JNI Example Using Visual C++ Cl.exe
Aim
The aim of this JNI tutorial is to use the Java Native Interface JNI to call a pure java callback from a native C++ function. It is slightly more complicated that just calling a native function, but will better demonstrate some of the JNI functionality. We will be using the Visual C++ cl.exe without the IDE to compile the C++ DLL that will contain the JNI implementations. Leave any questions or problems as comments and I will endeavour to answer them.
Assumptions
This article assumes that you have a compatible JDK installed. For purposes of this example the the project directory is JNIExample. Also it is assumed that you have VC++ installed and configured. See Problems and Solutions Installing VC++ Express Edition, to install and run vcvars32.bat.
Versions used in this example
Links to these files can be found here
The JDK is installed in the "D:\jdk1.5.0" for this example. Please remember to substitute your own directories for these.The files used in this are given below.
JNIExample
_|_JNIExample.java
_|_JNICppImplementation.cpp
_|_CommonDatabasePool.cpp
Write and compile the Java code
Write and compile the C++ DLL
Run the example
The aim of this JNI tutorial is to use the Java Native Interface JNI to call a pure java callback from a native C++ function. It is slightly more complicated that just calling a native function, but will better demonstrate some of the JNI functionality. We will be using the Visual C++ cl.exe without the IDE to compile the C++ DLL that will contain the JNI implementations. Leave any questions or problems as comments and I will endeavour to answer them.
Assumptions
This article assumes that you have a compatible JDK installed. For purposes of this example the the project directory is JNIExample. Also it is assumed that you have VC++ installed and configured. See Problems and Solutions Installing VC++ Express Edition, to install and run vcvars32.bat.
Versions used in this example
| Sofware/Component | Image |
| Windows XP SP2 | N/A |
| Java j2sdk 1.5 | N/A |
| Visual Studio Express Editions 2008 VC++ | N/A |
The JDK is installed in the "D:\jdk1.5.0" for this example. Please remember to substitute your own directories for these.The files used in this are given below.
JNIExample
_|_JNIExample.java
_|_JNICppImplementation.cpp
_|_CommonDatabasePool.cpp
Write and compile the Java code
- Write the javacode and save it as JNIExample.java in your working directory. The SetCallback method will be in the C++ dll and it will in turn call the Callback method. The static keyword is to make sure the dll is loaded once.
1. import java.util.*; 2. 3. public class JNIExample{ 4. static{ 5. try{ 6. System.loadLibrary("jnicpplib"); 7. }catch(Exception e){ 8. System.out.println(e.toString()); 9. } 10. } 11. 12. public native void SetCallback(JNIExample jniexample); 13. 14. 15. public static void main(String args[]){ 16. (new JNIExample()).go(); 17. } 18. 19. public void go(){ 20. SetCallback(this); 21. } 22. 23. //This will be called from inside the native method 24. public String Callback(String msg){ 25. return "Java Callback echo:" +msg; 26. } 27. }
Hide line numbers
`
- Now open a promt to this directory and compile the java code
..JNIExample>javac JNIExample.java
- Now run javah to create the required header file. This should create the JNIExample.h file.
..JNIExample>javah JNIExample
- Finally for completeness run the javap command. This command will give you the method signatures. You will need the method signature for Callback in your C++ file.
..JNIExample>javap -s JNIExample
Compiled from "JNIExample.java"
public class JNIExample extends java.lang.Object{
public JNIExample();
Signature: ()V
public native void SetCallback(JNIExample);
Signature: (LJNIExample;)V
public static void main(java.lang.String[]);
Signature: ([Ljava/lang/String;)V
public void go();
Signature: ()V
public java.lang.String Callback(java.lang.String);
Signature: (Ljava/lang/String;)Ljava/lang/String;
static {};
Signature: ()V
}
Write and compile the C++ DLL
- Create the JNICppImplementation.cpp file. As you can see this maps to the SetCallback function. Also note that we will be calling the Callback funtion in our java class with the char array "hello jni." The this pointer is passed to this native function as classref.
Note that we have included the JNIExample.h file that was generated from javah.1. #include "JNIExample.h" 2. 3. 4. JNIEXPORT void JNICALL Java_JNIExample_SetCallback (JNIEnv * jnienv, jobject jobj, jobject classref) 5. { 6. jclass jc = jnienv->GetObjectClass(classref); 7. 8. jmethodID mid = jnienv->GetMethodID(jc, "Callback","(Ljava/lang/String;)Ljava/lang/String;"); 9. 10. jstring result = (jstring)jnienv->CallObjectMethod(classref, mid, jnienv->NewStringUTF("hello jni")); 11. 12. const char * nativeresult = jnienv->GetStringUTFChars(result, 0); 13. 14. printf("Echo from Setcallback: %s", nativeresult); 15. 16. jnienv->ReleaseStringUTFChars(result, nativeresult); 17. 18. }
Hide line numbers
- Compile the dll using a command prompt and cl.exe. Make sure you have run vcvars32 prior to this. Also, remember to substitute your local jdk header file directories for the ones below.
..JNIExample>cl -o jnicpplib.dll JNICppImplementation.cpp /I D:\jdk1.5.0\include /I D:\jdk1.5.0\include\win32 /link /DLL
Run the example
- Open a prompt into your working directory and run the example.
..JNIExample>java JNIExample
- You should see a message Echo from SetCallback: Java Callback echo:hello jni on your screen. The native method SetCallback calls the java Callback method with the char array "hello jni." The Callback appends Java Callback echo: and returns. The SetCallback then appends Echo from SetCallback: to this and prints it out.
Connecting to Glassfish/Sun JMS Using C++ / C API
Aim
The aim of this tutorial is to use Sun's Message Queue 4.3 C-API to connect to a JMS topic on a Glassfish server. This is a fairly simple as we will compile the examples in the package and sun them agaisnst a Queue created in Glassfish. This example is on Windows using cl.exe. Leave any questions or problems as comments and I will endeavour to answer them. I will not be creating any source files as the ones provided in the examples are the simplest and cannot be further reduced.
Assumptions
This article assumes that you have Galssfish 2 installed and a domain configured. Please see Installing and Setting up Glassfish 2 for more details. For purposes of this example the glassfish domain is running on port 8082 and the project directory is examples.
For those of you who are familiar with the JMS Example using Glassfish and Remote Client example, you can go directly to the Compiling and Running sections as we are going to connect to the "jms/MyFirstTopic" topic in the example. If not follow the steps to setup a JMS
Versions used in this example
Links to these files can be found here
Download and Unzip/Install Message Queue 4.3
Create a Topic in Glassfish - if you haven't already
Compile the Consupmer and Producer
Running the example
The aim of this tutorial is to use Sun's Message Queue 4.3 C-API to connect to a JMS topic on a Glassfish server. This is a fairly simple as we will compile the examples in the package and sun them agaisnst a Queue created in Glassfish. This example is on Windows using cl.exe. Leave any questions or problems as comments and I will endeavour to answer them. I will not be creating any source files as the ones provided in the examples are the simplest and cannot be further reduced.
Assumptions
This article assumes that you have Galssfish 2 installed and a domain configured. Please see Installing and Setting up Glassfish 2 for more details. For purposes of this example the glassfish domain is running on port 8082 and the project directory is examples.
For those of you who are familiar with the JMS Example using Glassfish and Remote Client example, you can go directly to the Compiling and Running sections as we are going to connect to the "jms/MyFirstTopic" topic in the example. If not follow the steps to setup a JMS
Versions used in this example
| Sofware/Component | Image |
| Windows XP SP2 | N/A |
| Glassfish 2 | glassfish-installer-v2.1-b60e-windows.jar |
| Visual C++ 2008 Express Edition | N/A |
| Message Queue 4.3 | mq4_3-installer-WINNT.zip |
Download and Unzip/Install Message Queue 4.3
- Download and unzip Message Queue 4.3. Note that i'm going to download and unzip this package. I'm not going to install it as I don't want a full Message Queue. I'm using Glassfish for that. For this example, the archive is extracted to d:\mq4_3-installer.
- Navigate to d:\mq4_3-installer\Product\WINDOWS\WINDOWS XP\X86\5.1\Packages and extract the mq-capi.zip to your working diretory. You should see a structure such as below. We will be working inside the mq\examples directory.
mq\bin
mq\examples
mq\include
mq\lib
Create a Topic in Glassfish - if you haven't already
- Login to the Glassfish admin console.
- Now select Resources -> JMS Resources -> Destination Resources. Select New
`
- Enter jms/MyFirstTopic as the JNDI name. Enter MyFirstTopic into the Physical Destination Name and select javax.jms.Topic from the "Resource Type" dropdown. Select OK. The physical destination is what you would use to connect outside of JNDI - forexample using the JMS C-API.
Compile the Consupmer and Producer
- Open a prompt into the mq\examples\C\producer_consumer directory you extracted in the previous section
- Compile the Consumer
..mq\examples\C\producer_consumer>cl /MD -DWIN32 -I..\..\..\include Consumer.c /NODEFAULTLIB ..\..\..\lib\mqcrt.lib
- Compile the Producer
..mq\examples\C\producer_consumer>cl /MD -DWIN32 -I..\..\..\include Producer.c /NODEFAULTLIB ..\..\..\lib\mqcrt.lib
Running the example
- Add the mq\lib directory to your PATH. For this example I have extracted the mq-capi.zip under c:\temp. Replace this path with your local ppath!
..mq\examples\C\producer_consumer>set PATH=%PATH%;d:\temp\mq\lib
- Now run the consumer.
..mq\examples\C\producer_consumer>consumer -h localhost -p 7676 -t topic -d MyFirstTopic
- Open a new prompt and navigate to the ..mq\examples\C\producer_consumer directory. Now run the producer from here.
..mq\examples\C\producer_consumer>producer -h localhost -p 7676 -t topic -d MyFirstTopic
- Type some text in the producer's promt and it will appear on the consumers console.
- If you already have the JMS Example using Glassfish and Remote Client tutorial configured, then you can send and receive messages via the JNDI to the C-API and vice versa. Now that's pretty cool.
Oracle C++ OCI Database Connection Pool
Aim
The aim of this bit of code is to implement an Oracle C++ (OCCI) Database Pool in Windows. A Database pool is normally used by applications to speed up the process of getting a Connection.
If you are just starting with Oracle C++ OCCI and would like a simple tutorial first the please go to Oracle OCCI C++ Database Example.
If you would like to see this DBPool implemented in MySQL the visit MySQL Connector C++ Database Pool .
Assumptions
This article assumes that you have an Oracle database installed and running and you have downloaded and installed/unzipped the Oracle Client which contains the header files and libs required. For purposes of this example the the project directory is CppDatabasePool. Also it is assumed that you have VC++ installed and configured. See Problems and Solutions Installing VC++ Express Edition, to install and run vcvars32.bat.
Versions used in this example
Links to these files can be found here
Oracle client is installed (expanded) in the "D:\oracle" directory for this example. Please remember to substitute your own directories for these.
NOTE: OCCI uses tnsnames.ora to connect to the database. So make sure you have this file configured with the database details you wish to connect to.
The files used in this are given below.
Workspace
_|_CrossHelper.h
_|_CrossHelper.cpp
_|_CommonDatabasePool.cpp
_|_mysql
_|__|_MySQLPool.h
_|__|_MySQLPool.cpp
_|_oracle
_|__|_OraclePool.h
_|__|_OraclePool.cpp
_|_sqlserver
_|__|_SQLSvrPool.h
_|__|_SQLSvrPool.cpp
_|_examples
_|__|_ExampleOracle.cpp
_|__|_ExampleMySQL.cpp
_|__|_ExampleSQLSvr.cpp
_|__|_makefile.oracle
_|__|_makefile.mysql
_|__|_makefile.sqlsvr
You can download the zipped files here.
CrossHelper.h and CrossHelper.cpp - Define and implement the crossplatform functionality between windows and linux - I haven't finished the linux part yet.
CommonDatabasePool.cpp - This is the primary file that has a template and a map that stores the cached connections and a thread that runs to ping the database connections to keep them alive and prevent an inactive timeout. The idea is to potentially be able to use this template with different database implementations .
oracle/OraclePool.h and oracle/OraclePool.cpp - These classes actually inherit from the template above and implement the Oracle specific tasks. You will be using this class but not editing it.
examples/ExampleOracle.cpp - This has an example of how you use the pool.
makefile.oracle - Used to build the example. DO NOT forget the "/D WINDOWSXX" flag as this is needed to compile the widows version. Also remember to substitute your local directories for the ones in the bat file. There should be the oracle oci include directory and the oraocci10.lib binary for compile.
Below is the ExampleOracle.cpp file.
As you can see the basic steps are..
Compiling and running the code
The aim of this bit of code is to implement an Oracle C++ (OCCI) Database Pool in Windows. A Database pool is normally used by applications to speed up the process of getting a Connection.
If you are just starting with Oracle C++ OCCI and would like a simple tutorial first the please go to Oracle OCCI C++ Database Example.
If you would like to see this DBPool implemented in MySQL the visit MySQL Connector C++ Database Pool .
Assumptions
This article assumes that you have an Oracle database installed and running and you have downloaded and installed/unzipped the Oracle Client which contains the header files and libs required. For purposes of this example the the project directory is CppDatabasePool. Also it is assumed that you have VC++ installed and configured. See Problems and Solutions Installing VC++ Express Edition, to install and run vcvars32.bat.
Versions used in this example
| Sofware/Component | Image |
| Windows XP SP2 | N/A |
| Oracle Database | N/A |
| Oracle Client | 10201_client_win32.zip |
| Visual Studio Express Editions 2008 VC++ | N/A |
Oracle client is installed (expanded) in the "D:\oracle" directory for this example. Please remember to substitute your own directories for these.
NOTE: OCCI uses tnsnames.ora to connect to the database. So make sure you have this file configured with the database details you wish to connect to.
The files used in this are given below.
Workspace
_|_CrossHelper.h
_|_CrossHelper.cpp
_|_CommonDatabasePool.cpp
_|_mysql
_|__|_MySQLPool.h
_|__|_MySQLPool.cpp
_|_oracle
_|__|_OraclePool.h
_|__|_OraclePool.cpp
_|_sqlserver
_|__|_SQLSvrPool.h
_|__|_SQLSvrPool.cpp
_|_examples
_|__|_ExampleOracle.cpp
_|__|_ExampleMySQL.cpp
_|__|_ExampleSQLSvr.cpp
_|__|_makefile.oracle
_|__|_makefile.mysql
_|__|_makefile.sqlsvr
You can download the zipped files here.CrossHelper.h and CrossHelper.cpp - Define and implement the crossplatform functionality between windows and linux - I haven't finished the linux part yet.
CommonDatabasePool.cpp - This is the primary file that has a template and a map that stores the cached connections and a thread that runs to ping the database connections to keep them alive and prevent an inactive timeout. The idea is to potentially be able to use this template with different database implementations .
oracle/OraclePool.h and oracle/OraclePool.cpp - These classes actually inherit from the template above and implement the Oracle specific tasks. You will be using this class but not editing it.
examples/ExampleOracle.cpp - This has an example of how you use the pool.
makefile.oracle - Used to build the example. DO NOT forget the "/D WINDOWSXX" flag as this is needed to compile the widows version. Also remember to substitute your local directories for the ones in the bat file. There should be the oracle oci include directory and the oraocci10.lib binary for compile.
Below is the ExampleOracle.cpp file.
1. /* Copyright 2009 Righteous Ninja AKA P.S. Ching*/ 2. #include <iostream> 3. #include "..\oracle\OraclePool.h" 4. 5. using namespace std; 6. 7. int main(){ 8. try{ 9. 10. OraclePool* oraclepool = new OraclePool( "MYDATBASE", //database (TNS) 11. "gldbuser", //username 12. "gldbuser", //password 13. 300, //keepalive timeout (seconds) 14. "select 0 from dual"); //keepalive statement 15. 16. /*Create a pool that will have 3 cached connections and will swell upto a 17. total of 5 connections. Returns the number of cached connections or -1 on error 18. */ 19. if(oraclepool->CreatePool(3, 5)<=0){ 20. cout<<"Error creating database pool\n"; 21. cout<<oraclepool->GetLastPoolError()<<endl; //If it's asystem error 22. goto EXAMPLE_END; 23. } 24. 25. /*Dispaly the pool information*/ 26. oraclepool->DisplayInfo(cout); 27. 28. oracle::occi::Connection *con; 29. oracle::occi::Statement* stmt; 30. oracle::occi::ResultSet* res; 31. 32. /*Get a connection from the pool*/ 33. if((con=oraclepool->GetConnectionFromPool())==0){ 34. cout<<"You have reached the maximum amout allowed - 5 in this example\n"; 35. goto EXAMPLE_END; 36. } 37. /*Select the schema and do a query. DO NOT delete the 'con' after the query. 38. This will be released via the ReleaseConnectionToPool back to the pool 39. */ 40. stmt = con->createStatement("select * from example"); 41. res = stmt->executeQuery(); 42. while (res->next()) 43. std::cout<<res->getInt(1)<<" "<<res->getString(2)<<std::endl; 44. 45. stmt->closeResultSet(res); 46. con->terminateStatement(stmt); 47. 48. /*Dispaly the pool information*/ 49. oraclepool->DisplayInfo(cout); 50. 51. /*Release the connection back into the pool*/ 52. oraclepool->ReleaseConnectionToPool(con); 53. 54. /*Dispaly the pool information*/ 55. oraclepool->DisplayInfo(cout); 56. 57. 58. EXAMPLE_END: 59. 60. /*Destroy the database pool*/ 61. if(oraclepool->DestroyPool()>0){ 62. cout<<"There are still some un-release connections in the pool\n"; 63. } 64. 65. delete oraclepool; 66. 67. char c; 68. cout<<"Enter character to exit\n"; 69. cin>>c; 70. 71. }catch(oracle::occi::SQLException &e){ 72. std::cout<<e.what(); 73. } 74. 75. return 0; 76. }Hide line numbers |
As you can see the basic steps are..
- OraclePool* oraclepool = new OraclePool("mydatabase", "username","password", 300, "select 0 from dual");
The keepalive thread will issue the "select 0 from dual" statement every 300 seconds across all the inactive connections in the cache to keep them alive.
- oraclepool ->CreatePool(3, 5);
This creates a cache with 3 stored connections that will swell to a max of 5 connections when required. If you go above 5 connections without releasing any then you will get a 0 when you next call GetConnectionFromPool().
- con=oraclepool ->GetConnectionFromPool()
- Do stuff with the connection. Remember not to release or delete this connection as it will be returned to the pool.
- oraclepool ->ReleaseConnectionToPool(con);
- oraclepool ->DestroyPool();
Compiling and running the code
- Open a command prompt and go to the "examples" direcotory. Compile the files by running nmake. Make sure to substitute your local directories for the ones in the file. There should be the oracle oci include directory and the oraocci10.lib binary for compile.
..\CppDatabasePool\examples>nmake -f makefile.oracle
- Add these paths to your existing path so that the executable can find the required libraries. Again, don't forget to replace the directories with the ones on your local machine. Basically you need to give the 'bin' diretory and the 'oci\lib\msvc\vc7' directory in your of your Oracle client installation.
..\CppDatabasePool\examples>set path=%path%;D:\oracle\product\10.2.0\client_1\oci\lib\msvc\vc7
..\CppDatabasePool\examples>set path=%path%;D:\oracle\product\10.2.0\client_1\BIN
- In the command prompt run 'testoracle.exe.' Make sure the database parameters are your own. ie. username, pasword, tns name etc.
MySQL Connector C++ Database Connection Pool
Aim
The aim of this bit of code is to implement a MySQL connector C++ Database Pool in Windows. A Database pool is normally used by applications to speed up the process of getting a Connection. For an introduction to using MySQL Connector C++ see MySQL Connector C++ Example - Windows cl.exe (VC++).
If you'd like to see this in DBPool implemented for Oracle, then visit Oracle C++ OCI Database Pool .
Assumptions
This article assumes that you have the MySQL database installed and running and you have donwloaded and unzipped/installed the MySQL Connector C++ API. For purposes of this example the the project directory is CppDatabasePool. Also it is assumed you have VC++ installed and configured. See Problems and Solutions Installing VC++ Express Edition, to install and run vcvars32.bat.
Versions used in this example
Links to these files can be found here
MySQL is installed (expanded) in the "D:\downloads\mysql\mysql-5.1.32-win32" for this example. Also MySQL Connector C++ is expanded in the "D:\downloads\mysql-connector-c++-noinstall-1.0.5-win32" directory. Please remember to substitute your own directories for these.
The files used in this are given below.
Workspace
_|_CrossHelper.h
_|_CrossHelper.cpp
_|_CommonDatabasePool.cpp
_|_mysql
_|__|_MySQLPool.h
_|__|_MySQLPool.cpp
_|_oracle
_|__|_OraclePool.h
_|__|_OraclePool.cpp
_|_sqlserver
_|__|_SQLSvrPool.h
_|__|_SQLSvrPool.cpp
_|_examples
_|__|_ExampleOracle.cpp
_|__|_ExampleMySQL.cpp
_|__|_ExampleSQLSvr.cpp
_|__|_makefile.oracle
_|__|_makefile.mysql
_|__|_makefile.slqsvr
You can download the zipped files here.
CrossHelper.h and CrossHelper.cpp - Define and implement the crossplatform functionality between windows and linux - I haven't finished the linux part yet.
CommonDatabasePool.cpp - This is the primary file that has a template and a map that stores the cached connections and a thread that runs to ping the database connections to keep them alive and prevent an inactive timeout. The idea is to potentially be able to use this template with other implementations and not just MySQL Connector C++ only.
mysql/MySQLPool.h and mysql/MySQLPool.cpp - These classes actually inherit from the template above and implement the MySQL specific tasks. You will be using this class but not editing it.
examples/ExampleMySQL.cpp - This has an example of how you use the pool.
buildmysql.bat - Used to build the example. DO NOT forget the "/D WINDOWSXX" flag as this is needed to compile the widows version. Also remember to substitute your local directories for the ones in the file. They should be the mysql connector c++ include directory and the mysqlcppconn.lib.
Below is the ExampleMySQL.cpp file.
As you can see the basic steps are..
Compiling and running the code
Back to the tutorial trail | Home
The aim of this bit of code is to implement a MySQL connector C++ Database Pool in Windows. A Database pool is normally used by applications to speed up the process of getting a Connection. For an introduction to using MySQL Connector C++ see MySQL Connector C++ Example - Windows cl.exe (VC++).
If you'd like to see this in DBPool implemented for Oracle, then visit Oracle C++ OCI Database Pool .
Assumptions
This article assumes that you have the MySQL database installed and running and you have donwloaded and unzipped/installed the MySQL Connector C++ API. For purposes of this example the the project directory is CppDatabasePool. Also it is assumed you have VC++ installed and configured. See Problems and Solutions Installing VC++ Express Edition, to install and run vcvars32.bat.
Versions used in this example
| Sofware/Component | Image |
| Windows XP SP2 | N/A |
| MySQL Database | mysql-noinstall-5.1.32-win32.zip |
| MySQL Connector C++ | mysql-connector-c++-noinstall-1.0.5-win32.zip |
| Visual Studio Express Editions 2008 VC++ | N/A |
MySQL is installed (expanded) in the "D:\downloads\mysql\mysql-5.1.32-win32" for this example. Also MySQL Connector C++ is expanded in the "D:\downloads\mysql-connector-c++-noinstall-1.0.5-win32" directory. Please remember to substitute your own directories for these.
The files used in this are given below.
Workspace
_|_CrossHelper.h
_|_CrossHelper.cpp
_|_CommonDatabasePool.cpp
_|_mysql
_|__|_MySQLPool.h
_|__|_MySQLPool.cpp
_|_oracle
_|__|_OraclePool.h
_|__|_OraclePool.cpp
_|_sqlserver
_|__|_SQLSvrPool.h
_|__|_SQLSvrPool.cpp
_|_examples
_|__|_ExampleOracle.cpp
_|__|_ExampleMySQL.cpp
_|__|_ExampleSQLSvr.cpp
_|__|_makefile.oracle
_|__|_makefile.mysql
_|__|_makefile.slqsvr
You can download the zipped files here.CrossHelper.h and CrossHelper.cpp - Define and implement the crossplatform functionality between windows and linux - I haven't finished the linux part yet.
CommonDatabasePool.cpp - This is the primary file that has a template and a map that stores the cached connections and a thread that runs to ping the database connections to keep them alive and prevent an inactive timeout. The idea is to potentially be able to use this template with other implementations and not just MySQL Connector C++ only.
mysql/MySQLPool.h and mysql/MySQLPool.cpp - These classes actually inherit from the template above and implement the MySQL specific tasks. You will be using this class but not editing it.
examples/ExampleMySQL.cpp - This has an example of how you use the pool.
buildmysql.bat - Used to build the example. DO NOT forget the "/D WINDOWSXX" flag as this is needed to compile the widows version. Also remember to substitute your local directories for the ones in the file. They should be the mysql connector c++ include directory and the mysqlcppconn.lib.
Below is the ExampleMySQL.cpp file.
1. /* Copyright 2009 Righteous Ninja AKA P.S. Ching*/ 2. #include <iostream> 3. #include "MySQLPool.h" 4. 5. using namespace std; 6. 7. int main(){ 8. 9. try{ 10. 11. MySQLPool* mysqlpool = new MySQLPool( "tcp://127.0.0.1:3306", //database url 12. "root", //username 13. "root", //password 14. 300, //keepalive timeout (seconds) 15. "select 0 from dual"); //keepalive statement 16. 17. /*Create a pool that will have 3 cached connections and will swell upto a 18. total of 5 connections. Returns the number of cached connections or -1 on error 19. */ 20. if(mysqlpool->CreatePool(3, 5)<=0){ 21. cout<<"Error creating database pool\n"; 22. cout<<mysqlpool->GetLastPoolError()<<endl; 23. goto EXAMPLE_END; 24. } 25. 26. /*Dispaly the pool information*/ 27. mysqlpool->DisplayInfo(cout); 28. 29. 30. sql::Connection *con; 31. sql::Statement* stmt; 32. sql::ResultSet* res; 33. 34. /*Get a connection from the pool*/ 35. if((con=mysqlpool->GetConnectionFromPool())==0){ 36. cout<<"You have reached the maximum amout allowed - 5 in this example\n"; 37. goto EXAMPLE_END; 38. } 39. /*Select the schema and do a query. DO NOT delete the 'con' after the query. 40. This will be released via the ReleaseConnectionToPool back to the pool 41. */ 42. con->setSchema("test"); 43. stmt = con->createStatement(); 44. res = stmt->executeQuery("select * from example"); 45. while (res->next()) 46. std::cout<<res->getInt("id")<<" "<<res->getString("data")<<std::endl; 47. delete res; 48. delete stmt; 49. 50. /*Dispaly the pool information*/ 51. mysqlpool->DisplayInfo(cout); 52. 53. /*Release the connection back into the pool*/ 54. mysqlpool->ReleaseConnectionToPool(con); 55. 56. /*Dispaly the pool information*/ 57. mysqlpool->DisplayInfo(cout); 58. 59. /*Destroy the database pool*/ 60. if(mysqlpool->DestroyPool()>0){ 61. cout<<"There are still some un-release connections in the pool\n"; 62. } 63. 64. EXAMPLE_END: 65. 66. char c; 67. cout<<"Enter character to exit\n"; 68. cin>>c; 69. 70. }catch(sql::SQLException &e){ 71. std::cout<<e.what(); 72. } 73. 74. 75. return 0; 76. }Hide line numbers |
As you can see the basic steps are..
- MySQLPool* mysqlpool = new MySQLPool("tcp://127.0.0.1:3306", "username","password", 300, "select 0 from dual");
The keepalive thread will issue the "select 0 from dual" statement every 300 seconds across all the inactive connections in the cache to keep them alive.
- mysqlpool->CreatePool(3, 5);
This creates a cache with 3 stored connections that will swell to a max of 5 connections when required. If you go above 5 connections without releasing any then you will get a 0 when you next call GetConnectionFromPool().
- con=mysqlpool->GetConnectionFromPool()
- Do stuff with the connection. Remember not to release or delete the connection as it will be returned to the pool.
- mysqlpool->ReleaseConnectionToPool(con);
- mysqlpool->DestroyPool();
Compiling and running the code
- Open a command prompt and compile the files by running nmake Make sure to substitute your local directories for the ones in the file. These should be the mysql connector c++ include directory and the mysqlcppconn.lib.
..\CppDatabasePool\examples>nmake -f makefile.mysql
`
- Add these paths to your existing path so that the executable can find the required libraries. Again, don't forget to replace the directories with the ones on your local machine. Basically you need to give the 'bin' diretory of your MySQL database installation and the 'lib' directory in your MySQL Connector C++ directory.
..\CppDatabasePool\examples>set path=%path%;D:\downloads\mysql\mysql-5.1.32-win32\bin
..\CppDatabasePool\examples>set path=%path%;D:\downloads\mysql-connector-c++-noinstall-1.0.5-win32\lib
`
- In the command prompt run 'testmysql.exe.' Make sure the database parameters are your own. ie. username, pasword, url, and schema.
Back to the tutorial trail | Home
Entity CMP EJB Example in Glassfish - No Annotations
Aim
The aim of this EJB tutorial is to create a simple CMP (Container Managed Persistence) Entity Enterprise Java Bean or EJB, deploy it to a Glassfish server and then call it's remote interface via a java client. We will be building this bean from the ground up with an ejb-jar.xml and persistence.xml and without the use of Annotations( @Remote etc). Once you learn the basic you can take the short-cuts. Leave any questions or problems as comments and I will endeavour to answer them.
Assumptions
This article assumes that you have Galssfish 2 installed and a domain configured. Please see Installing and Setting up Glassfish 2 for more details. For purposes of this example the glassfish domain is running on port 8082. This also assumes that you have a database up and running with a JNDI database pool configured. For this example we are using a MySQL database with a pool configured in one of the previous tutorials -JNDI Database bool with MySQL. The project directory is EJBEntityCMPExample.
Versions used in this example
Links to these files can be found here
Although this is a quick 'helloworld' tutorial we will not sacrifice neatness for speed - so all the source files, class files etc will be kept in separate directories and as clean as possible. You will thank me for this later.
Create this webapp directory structure in your working directory- similar to something you would get from eclipse. The structure used in this example is given below. EJBEntityCMPExample will be referred to as your project or working directory. Create this structure.
EJBEntityCMPExample
_|_bean_src
_|__|_EntityBeanExample.java
_|__|_EntityBeanHomeExampleI.java
_|__|_EntityBeanExampleI.java
_|_bean_bin
_|__|_META-INF
_|__|__|_ejb-jar.xml
_|__|__|_sun-ejb-jar.xml
_|__|__|_persistence.xml
_|_client_src
_|__|_EntityBeanClient.java
_|_client_bin
The Glassfish app server is installed in the D:\downloads\glassfish directory for this tutorial.
JNDI-JBDC pool
Write and compile the Bean files
Deploy the EJB in Glassfish
We are going to take a short cut and deploy the bean_bin directory instead of jar-ring it up and deploying as a .war or .jar file.
Write and compile the Client
Running the client
Back to the tutorial trail | Home
The aim of this EJB tutorial is to create a simple CMP (Container Managed Persistence) Entity Enterprise Java Bean or EJB, deploy it to a Glassfish server and then call it's remote interface via a java client. We will be building this bean from the ground up with an ejb-jar.xml and persistence.xml and without the use of Annotations( @Remote etc). Once you learn the basic you can take the short-cuts. Leave any questions or problems as comments and I will endeavour to answer them.
Assumptions
This article assumes that you have Galssfish 2 installed and a domain configured. Please see Installing and Setting up Glassfish 2 for more details. For purposes of this example the glassfish domain is running on port 8082. This also assumes that you have a database up and running with a JNDI database pool configured. For this example we are using a MySQL database with a pool configured in one of the previous tutorials -JNDI Database bool with MySQL. The project directory is EJBEntityCMPExample.
Versions used in this example
| Sofware/Component | Image |
| Windows XP SP2 | N/A |
| Glassfish 2 | glassfish-installer-v2.1-b60e-windows.jar |
| JDK 1.5.0 | N/A |
Although this is a quick 'helloworld' tutorial we will not sacrifice neatness for speed - so all the source files, class files etc will be kept in separate directories and as clean as possible. You will thank me for this later.
Create this webapp directory structure in your working directory- similar to something you would get from eclipse. The structure used in this example is given below. EJBEntityCMPExample will be referred to as your project or working directory. Create this structure.
EJBEntityCMPExample
_|_bean_src
_|__|_EntityBeanExample.java
_|__|_EntityBeanHomeExampleI.java
_|__|_EntityBeanExampleI.java
_|_bean_bin
_|__|_META-INF
_|__|__|_ejb-jar.xml
_|__|__|_sun-ejb-jar.xml
_|__|__|_persistence.xml
_|_client_src
_|__|_EntityBeanClient.java
_|_client_bin
The Glassfish app server is installed in the D:\downloads\glassfish directory for this tutorial.
JNDI-JBDC pool
- This tutorial assumes that you already have the 'jdbc/MySQLPool' jndi dtabase pool configured and you have the table required. The table below is the entitybeanexample table. the id field is a primary key. Make sure you can access this table through the jdbc/jndi entry. See JNDI Database bool with MySQL if you wan't to learn how to do this. Our entity bean will map to this table.
id (INT) name (CHAR) 1 arabica 2 robusta
`
- For completeness I have added an axcertp from the dump of the 'entitybeanexample' table below. You can forget about the additional columns. All you need is the id and name.
1. CREATE TABLE `entitybeanexample` ( 2. `id` int(11) NOT NULL DEFAULT '0', 3. `name` char(32) DEFAULT NULL, 4. `description` char(32) DEFAULT NULL, 5. `stocklevel` int(11) DEFAULT NULL, 6. PRIMARY KEY (`id`) 7. ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 8. SET character_set_client = @saved_cs_client; 9. 10. -- 11. -- Dumping data for table `entitybeanexample` 12. -- 13. 14. LOCK TABLES `entitybeanexample` WRITE; 15. /*!40000 ALTER TABLE `entitybeanexample` DISABLE KEYS */; 16. INSERT INTO `entitybeanexample` VALUES (1,'arabica',NULL,0),(2,'robusta',NULL,0),(3,'liberica',NULL,0),(4,'bonnieri',NULL,0),(5,'ganja',NULL,NULL); 17. /*!40000 ALTER TABLE `entitybeanexample` ENABLE KEYS */; 18. UNLOCK TABLES;
Hide line numbers
Write and compile the Bean files
- Write the remote interface and save it under bean_src as EntityBeanExampleI.java.
1. package ejb.entitybeanexample; 2. 3. import java.rmi.*; 4. import javax.ejb.*; 5. 6. public interface EntityBeanExampleI extends EJBObject{ 7. 8. public Integer getId() throws RemoteException; 9. public void setId(Integer id) throws RemoteException; 10. 11. public String getName() throws RemoteException; 12. public void setName(String name) throws RemoteException; 13. }
Hide line numbers
`
- Write the home interface and save it under bean_src as EntityBeanHomeExampleI.java.
1. package ejb.entitybeanexample; 2. 3. import java.util.Collection; 4. import java.rmi.*; 5. import javax.ejb.*; 6. 7. public interface EntityBeanHomeExampleI extends EJBHome{ 8. public EntityBeanExampleI create(Integer id, String name) throws CreateException, RemoteException; 9. public EntityBeanExampleI findByPrimaryKey(Integer id) throws FinderException, RemoteException; 10. public Collection findByNameLike(String s) throws FinderException, RemoteException;; 11. }
Hide line numbers
`
- Complete the bean implementation and save it under bean_src as EntityBeanExample.java.
1. package ejb.entitybeanexample; 2. 3. import javax.ejb.*; 4. import java.io.Serializable; 5. import java.util.*; 6. import java.rmi.*; 7. 8. public abstract class EntityBeanExample implements EntityBean { 9. 10. public abstract Integer getId(); 11. public abstract void setId(Integer id); 12. 13. public abstract String getName(); 14. public abstract void setName(String name); 15. 16. public void ejbLoad() {} 17. public void ejbStore() {} 18. public void ejbActivate() {} 19. public void ejbPassivate() {} 20. public void setEntityContext(EntityContext ctx) {} 21. public void unsetEntityContext() {} 22. public void ejbRemove() throws RemoveException {} 23. 24. public void ejbPostCreate(Integer id, String name) throws CreateException {} 25. 26. public Integer ejbCreate(Integer id, String name) throws CreateException { 27. setId(id); 28. setName(name); 29. return null; 30. } 31. }
Hide line numbers
`
- Compile the code and install the classes into the bean_bin using the cmd below.
..workspace\EJBEntityCMPExample\bean_src>javac -extdirs D:\downloads\glassfish\lib -d ..\bean_bin *.java
`
- Create the deployment descriptor ejb-jar.xml. Save this under the bean_bin/META-INF directory. Note that the abstract name of the table is called 'beanstore.'
1. <?xml version="1.0" encoding="UTF-8"?> 2. <ejb-jar> 3. <display-name>Simple Entity Bean</display-name> 4. <enterprise-beans> 5. <entity> 6. <description>Simple CMP Entity bean example</description> 7. <ejb-name>EntityBeanExample</ejb-name> 8. <home>ejb.entitybeanexample.EntityBeanHomeExampleI</home> 9. <remote>ejb.entitybeanexample.EntityBeanExampleI</remote> 10. <ejb-class>ejb.entitybeanexample.EntityBeanExample</ejb-class> 11. <persistence-type>Container</persistence-type> 12. <prim-key-class>java.lang.Integer</prim-key-class> 13. <reentrant>false</reentrant> 14. <cmp-version>2.x</cmp-version> 15. <abstract-schema-name>beanstore</abstract-schema-name> 16. <cmp-field> 17. <field-name>id</field-name> 18. </cmp-field> 19. <cmp-field> 20. <field-name>name</field-name> 21. </cmp-field> 22. <primkey-field>id</primkey-field> 23. <query> 24. <query-method> 25. <method-name>findByNameLike</method-name> 26. <method-params> 27. <method-param>java.lang.String</method-param> 28. </method-params> 29. </query-method> 30. <ejb-ql>select object(e) from beanstore e where e.name like ?1</ejb-ql> 31. </query> 32. </entity> 33. </enterprise-beans> 34. </ejb-jar>
Hide line numbers
`
- Create the sun-ejb-jar.xml file and save this under the bean_bin\WEB-INF folder too. Note the jndi/jdbc name we're using for the database connection.
1. <?xml version="1.0" encoding="UTF-8"?> 2. <sun-ejb-jar> 3. <enterprise-beans> 4. <ejb> 5. <ejb-name>EntityBeanExample</ejb-name> 6. <jndi-name>ejb/entitybeanexample</jndi-name> 7. </ejb> 8. <cmp-resource> 9. <jndi-name>jdbc/MySQLPool</jndi-name> 10. </cmp-resource> 11. </enterprise-beans> 12. </sun-ejb-jar>
Hide line numbers
`
- Now the final persistence.xml file. This goes in the META-INF directory also. Note that are using oracle's toplink to provide the persistence mechanism.
1. <?xml version="1.0" encoding="UTF-8"?> 2. <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"> 3. <persistence-unit name="hello-world" transaction-type="JTA"> 4. <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider> 5. <jta-data-source>jdbc/MySQLPool</jta-data-source> 6. <class>ejb.entitybeanexample.EntityBeanExample</class> 7. <exclude-unlisted-classes>true</exclude-unlisted-classes> 8. </persistence-unit> 9. </persistence>
Hide line numbers
`
- Now cd into the bean_bin directory and jar up the files in preparation for deployment
..workspace\EJBEntityCMPExample\bean_bin>jar -cvf entitybeanexample.jar *
Deploy the EJB in Glassfish
We are going to take a short cut and deploy the bean_bin directory instead of jar-ring it up and deploying as a .war or .jar file.
- Login to the Glassfish admin console. Please see Installing and Setting up Glassfish 2
`
- Under Applications->EJB Modules select deploy. Under "Location" select "Packaged file to be uploaded to the server." Now navigate to your working directory (EJBEntityCMPExampleWorld), go to the bean_bin directory and select the 'entitybeanexample.jar' you created earlier. If there is a problem look at the server.log in the log directory in your Glassfish domain.
`
- To make sure go to the "bin" diretory under your glassfish installation and run asadmin with list-jndi-entries.
D:\downloads\glassfish\bin>asadmin list-jndi-entries --context ejb
Jndi Entries for server within ejb context:
mgmt: com.sun.enterprise.naming.TransientContext
entitybeanexample: javax.naming.Reference
Command list-jndi-entries executed successfully.
Write and compile the Client
- Write client and save it under the client_src direcotry as EntityBeanClient.java.
1. import java.util.*; 2. import java.io.*; 3. import javax.naming.*; 4. 5. import ejb.entitybeanexample.EntityBeanHomeExampleI; 6. import ejb.entitybeanexample.EntityBeanExampleI; 7. 8. public class EntityBeanClient { 9. 10. public static void main(String[] args) throws Exception{ 11. (new EntityBeanClient()).Go(); 12. } 13. 14. public void Go() throws Exception { 15. Properties props = new Properties(); 16. 17. props.put(Context.PROVIDER_URL,"iiop://127.0.0.1:3700"); 18. props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory"); 19. 20. InitialContext ctx = new InitialContext(props); 21. 22. EntityBeanHomeExampleI beanhome = (EntityBeanHomeExampleI) ctx.lookup("ejb/entitybeanexample"); 23. 24. EntityBeanExampleI bean= beanhome.findByPrimaryKey(2); 25. System.out.println(bean.getName()+" "+bean.getId()); 26. 27. bean = beanhome.create(new Integer(5), "ganja"); 28. //bean.remove(); 29. 30. Collection beans = beanhome.findByNameLike("arabica"); 31. Iterator i = beans.iterator(); 32. while(i.hasNext()){ 33. bean=(EntityBeanExampleI)i.next(); 34. System.out.println(bean.getId()+" "+bean.getName()); 35. } 36. 37. } 38. }
Hide line numbers
`
- open a promt to the "client_src" directory and Compile the code. Use the "-d" ooption to copy the class to the client_bin directory.
..workspace\EJBEntityCMPExample\client_src>javac -extdirs D:\downloads\glassfish\lib
-d ..\client_bin -cp ..\bean_bin EntityBeanClient.java
Running the client
- Open a command into the client_bin directory and run the application.
..workspace\EJBEntityCMPExample\client_bin>java -Djava.ext.dirs=D:\downloads\glassfish\lib -cp ..\bean_bin;. EntityBeanClient
`
- You should see the result in the console. Also if you noticed we created a bean/record and then deleted it in the client. You may wish to comment out some of this, recompile and run again to see what's happening in the database.
Back to the tutorial trail | Home
MySQL Connector C++ Example - Windows cl.exe (VC++)
Aim
The aim of this tutorial is to create a simple client that uses MySQL Connector C++ to connect to a MySQL database. We will be using the windows command line compiler cl.exe that comes with Visual Studio C++ for this example.Leave any questions or problems as comments and I will endeavour to answer them.
Assumptions
This article assumes that you have the MySQL database installed and running. purposes of this example the the project directory is MySQLConnectorCPPExample. Also you have VC++ installed and configured. See Problems and Solutions Installing VC++ Express Edition, to install and run vcvars32.bat.
Versions used in this example
Links to these files can be found here
MySQL is installed (expanded) in the "D:\downloads\mysql\mysql-5.1.32-win32" for this example. Also MySQL Connector C++ is expanded in the "D:\downloads\mysql-connector-c++-noinstall-1.0.5-win32" directory. Please remember to substitute your own directories for these. You can have a look at the MySQL Connector C++ Database Pool once you become familiar with this.
Download and unzip or install the MySQL Connector C++
Write and compile the Client
Back to the tutorial trail | Home
The aim of this tutorial is to create a simple client that uses MySQL Connector C++ to connect to a MySQL database. We will be using the windows command line compiler cl.exe that comes with Visual Studio C++ for this example.Leave any questions or problems as comments and I will endeavour to answer them.
Assumptions
This article assumes that you have the MySQL database installed and running. purposes of this example the the project directory is MySQLConnectorCPPExample. Also you have VC++ installed and configured. See Problems and Solutions Installing VC++ Express Edition, to install and run vcvars32.bat.
Versions used in this example
| Sofware/Component | Image |
| Windows XP SP2 | N/A |
| MySQL Database | mysql-noinstall-5.1.32-win32.zip |
| MySQL Connector C++ | mysql-connector-c++-noinstall-1.0.5-win32.zip |
| Visual Studio Express Editions 2008 VC++ | N/A |
MySQL is installed (expanded) in the "D:\downloads\mysql\mysql-5.1.32-win32" for this example. Also MySQL Connector C++ is expanded in the "D:\downloads\mysql-connector-c++-noinstall-1.0.5-win32" directory. Please remember to substitute your own directories for these. You can have a look at the MySQL Connector C++ Database Pool once you become familiar with this.
Download and unzip or install the MySQL Connector C++
- Download and install or unzip MySQL Connector C++
`
- For the purposes of this example I have a 'test' database running with a table called 'example' in MySQL. I have included an excerpt of the dump below for completeness.
1. CREATE TABLE `example` ( 2. `id` int(11) DEFAULT NULL, 3. `data` varchar(100) DEFAULT NULL 4. ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 5. SET character_set_client = @saved_cs_client; 6. 7. -- 8. -- Dumping data for table `example` 9. -- 10. 11. LOCK TABLES `example` WRITE; 12. /*!40000 ALTER TABLE `example` DISABLE KEYS */; 13. INSERT INTO `example` VALUES (1,'one'),(2,'two'),(3,'three'); 14. /*!40000 ALTER TABLE `example` ENABLE KEYS */; 15. UNLOCK TABLES;
Hide line numbers
Write and compile the Client
- Write the client and save it as mysqlexample.cpp in your working directory.
1. #include <stdlib.h> 2. #include <iostream> 3. 4. #include <cppconn/driver.h> 5. #include <cppconn/exception.h> 6. #include <cppconn/resultset.h> 7. #include <cppconn/statement.h> 8. #include <cppconn/prepared_statement.h> 9. 10. int main(){ 11. 12. sql::Driver *driver; 13. sql::Connection *con; 14. sql::Statement *stmt; 15. sql::ResultSet *res; 16. sql::PreparedStatement *pstmt; 17. 18. try{ 19. driver = get_driver_instance(); 20. con = driver->connect("tcp://127.0.0.1:3306", "root", "root"); 21. con->setSchema("test"); 22. 23. stmt = con->createStatement(); 24. stmt->execute("insert into example values(4,'four'),(5, 'five')"); 25. delete stmt; 26. 27. pstmt = con->prepareStatement("select * from example"); 28. res = pstmt->executeQuery(); 29. while (res->next()) 30. std::cout<<res->getInt("id")<<" "<<res->getString("data")<<std::endl; 31. delete res; 32. delete pstmt; 33. 34. pstmt = con->prepareStatement("delete from example where id=?"); 35. pstmt->setInt(1,4); 36. pstmt->executeUpdate(); 37. pstmt->setInt(1,5); 38. pstmt->executeUpdate(); 39. 40. delete pstmt; 41. 42. delete con; 43. }catch(sql::SQLException &e){ 44. std::cout<<e.what(); 45. } 46. }
Hide line numbers
`
- Open a prompt to the working directory and compile the code using the windows cl.exe compiler. Make sure to point '-I' (capital i) option to the include files and to include mysqlcppconn.lib
Substitue your local directories.
..workspace\MySQLConnectorCPPExample>cl mysqlexample.cpp D:\downloads\mysql-connector-c++-noinstall-1.0.5-win32\lib\mysqlcppconn.lib -I D:\downloads\mysql-connector-c++-noinstall-1.0.5-win32\include
`
- This should now create the mysqlexample.exe file. However if you run it now you might get some errors saying that some DLLs are missing.
`
- Add these paths to your existing path so that the executable can find the required libraries. Again, don't forget to replace the directories with the ones on your local machine. Basically you need to give the 'bin' diretory of your MySQL database installation and the 'lib' directory in your MySQL Connector C++ directory.
..\MySQLConnectorCPPExample>set path=%path%;D:\downloads\mysql\mysql-5.1.32-win32\bin
..\MySQLConnectorCPPExample>set path=%path%;D:\downloads\mysql-connector-c++-noinstall-1.0.5-win32\lib
`
- Now run the mysqlexample.exe and you should see the result. If there are any 'database not found' or 'credential' errors, you need to sort out your database. Make sure the tables are there and the username you are using has access to it.
Back to the tutorial trail | Home
Problem and Solution Installing VC++ Express Edition in Windows XP
I had some difficulty installing VC++ Express Edition on Windows XP 2002 sp2. Once you run the installer all the required files are successfully downloaded. It then starts installing but it kept getting stuck when trying to install .NET framework 3. A quick check in the 'add remove' finds that I currently have .NET framwork 2.x installed. I then uninstalled this and tried the VC++ EE installer again. It works fine!
Also don't forget to run vcvars32.bat in your 'C:\Program Files\Microsoft Visual Studio x.x\VC\bin>' directory, otherwise nmake and cl will give you errors.
Also don't forget to run vcvars32.bat in your 'C:\Program Files\Microsoft Visual Studio x.x\VC\bin>' directory, otherwise nmake and cl will give you errors.
Subscribe to:
Posts (Atom)
