Home » Eclipse Projects » DTP » Connect to MySql 5.0
Connect to MySql 5.0 [message #26460] |
Sat, 10 February 2007 08:12  |
Eclipse User |
|
|
|
Originally posted by: alnoor20000.yahoo.co.uk
Hi,
Is it possible to connect to MySql 5.0, I am using eclipse 3.2.1. If yes,
What plug-ins Do I need to install ,and is there any tutorial on how do to
make the conneciton.
Thanks.
|
|
|
Re: Connect to MySql 5.0 [message #26494 is a reply to message #26460] |
Sun, 11 February 2007 16:04   |
Eclipse User |
|
|
|
Jalal ha scritto:
> Hi,
> Is it possible to connect to MySql 5.0, I am using eclipse 3.2.1. If yes,
> What plug-ins Do I need to install ,and is there any tutorial on how do to
> make the conneciton.
> Thanks.
>
>
Hi,
I am using MySQL 5.0 with eclipse 3.2.0 and the
mysql-connector-java-3.1.13 is in the classpath; you can find it at
http://dev.mysql.com/downloads/ (now the
http://dev.mysql.com/downloads/connector/j/5.0.html is available).
To establish the connection I have used at first the DriverManager
class, and now the DataSource object.
DriverManager:
public static Connection creaConnessione()
{
try {
if (resourceBundle == null) {
try {
resourceBundle = ResourceBundle.getBundle("db");
} catch (Exception e) {
visualizzaErrore();
}
}
dbProvider = getDbProvider();
// postgreSQL
if (dbProvider.equals(postgreSQL)) {
..... posgreSQL Statements....
} else if (dbProvider.equals(MySQL)) {
DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
String connessione = resourceBundle.getString("mconnessione");
String database = resourceBundle.getString("mdatabase");
String user = resourceBundle.getString("muser");
String pwd = resourceBundle.getString("mpwd");
con = DriverManager.getConnection(connessione + database,
user, pwd);
// DB2
} else if (dbProvider.equals(DB2)) {
... DB2 Statements ...
// Sconosciuto
} else {
System.err.println("Database sconosciuto - controllare
db.properties ");
}
return con;
} catch(java.sql.SQLException e) {
System.err.print("Connessione database non riuscita: ");
System.err.println(e.getMessage());
}
return null;
}
public static String getDbProvider() {
if (resourceBundle == null) {
try {
resourceBundle = ResourceBundle.getBundle("db");
} catch (Exception e) {
visualizzaErrore();
}
}
return resourceBundle.getString("dbprovider");
}
Now I use a DataSource object to establish a PooledConnection; I have
registered the MysqlConnectionPoolDataSource in the File System, and
this is the code to establish the connection:
/**
* Crea la connessione con il database tramite una Data Source
*
*/
public static Connection creaPoolConn()
{
if (pcon == null) {
pcon = creaPCon();
}
try {
con = pcon.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
/**
* Crea la PooledConnection
*
*/
public static PooledConnection creaPCon()
{
dbProvider = getDbProvider();
try {
Context context = createContext();
// MySQL
if (dbProvider.equals(MySQL)) {
MysqlConnectionPoolDataSource dsource =
(MysqlConnectionPoolDataSource) context.lookup("mydatabase");
pcon = dsource.getPooledConnection();
// DB2
} else if (dbProvider.equals(DB2)) {
... DB2 Statements ...
} else {
System.err.println("Database sconosciuto -
controllare db.properties ");
}
} catch (Exception e) {
e.printStackTrace();
}
return pcon;
}
private static Context createContext() throws NamingException {
Context context = null;
try {
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.setProperty(Context.PROVIDER_URL, "file:E:/JNDI/JDBC");
context = new InitialContext(env);
} catch (Exception e) {
e.printStackTrace();
}
return context;
}
The resourceBundle refers to the db.properties file:
# Configurazione DataBase e connessione
# Database/connessione/Driver per MySQL
mconnessione = jdbc:mysql://localhost:3306/
mdatabase = mydatabase
muser = myuser
mpwd = mypwd
dbprovider = MySQL
To register the DataSource and access it from File System, you must
obtain JNDI classes that support the file system, for example Sun's
fscontext.jar (which requires providerutil.jar as well) and add these to
your classpath (See the Java Naming and Directory Interface(TM) tutorial
at http://java.sun.com/docs/books/tutorial/jndi/index.html).
A tutorial on JDBC is here:
http://java.sun.com/docs/books/tutorial/jdbc/TOC.html
Hope this helps
Riccardo Cattania
www.riccardocattania.net
|
|
|
Re: Connect to MySql 5.0 [message #26525 is a reply to message #26494] |
Sun, 11 February 2007 17:50   |
Eclipse User |
|
|
|
Originally posted by: alnoor20000.yahoo.co.uk
Thanks alot, that is really helpful.
"Riccardo Cattania" <riccardocattania@alice.it> wrote in message
news:eqo0ca$uk9$1@utils.eclipse.org...
> Jalal ha scritto:
>> Hi,
>> Is it possible to connect to MySql 5.0, I am using eclipse 3.2.1. If yes,
>> What plug-ins Do I need to install ,and is there any tutorial on how do
>> to make the conneciton.
>> Thanks.
> Hi,
> I am using MySQL 5.0 with eclipse 3.2.0 and the
> mysql-connector-java-3.1.13 is in the classpath; you can find it at
> http://dev.mysql.com/downloads/ (now the
> http://dev.mysql.com/downloads/connector/j/5.0.html is available).
>
> To establish the connection I have used at first the DriverManager class,
> and now the DataSource object.
>
> DriverManager:
>
> public static Connection creaConnessione()
> {
> try {
> if (resourceBundle == null) {
> try {
> resourceBundle = ResourceBundle.getBundle("db");
> } catch (Exception e) {
> visualizzaErrore();
> }
> }
> dbProvider = getDbProvider();
> // postgreSQL
> if (dbProvider.equals(postgreSQL)) {
> ..... posgreSQL Statements....
> } else if (dbProvider.equals(MySQL)) {
> DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
> String connessione = resourceBundle.getString("mconnessione");
> String database = resourceBundle.getString("mdatabase");
> String user = resourceBundle.getString("muser");
> String pwd = resourceBundle.getString("mpwd");
> con = DriverManager.getConnection(connessione + database, user,
> pwd);
> // DB2 } else if (dbProvider.equals(DB2)) {
> ... DB2 Statements ...
> // Sconosciuto
> } else {
> System.err.println("Database sconosciuto - controllare
> db.properties ");
> }
> return con;
> } catch(java.sql.SQLException e) {
> System.err.print("Connessione database non riuscita: ");
> System.err.println(e.getMessage());
> }
> return null; }
> public static String getDbProvider() {
> if (resourceBundle == null) {
> try {
> resourceBundle = ResourceBundle.getBundle("db");
> } catch (Exception e) {
> visualizzaErrore();
> }
> }
> return resourceBundle.getString("dbprovider");
> }
>
>
> Now I use a DataSource object to establish a PooledConnection; I have
> registered the MysqlConnectionPoolDataSource in the File System, and this
> is the code to establish the connection:
>
> /**
> * Crea la connessione con il database tramite una Data Source
> *
> */
> public static Connection creaPoolConn()
> {
> if (pcon == null) {
> pcon = creaPCon();
> }
> try {
> con = pcon.getConnection();
> } catch (SQLException e) {
> e.printStackTrace();
> }
> return con;
> }
> /**
> * Crea la PooledConnection
> *
> */
>
> public static PooledConnection creaPCon()
> {
> dbProvider = getDbProvider();
> try {
> Context context = createContext();
> // MySQL
> if (dbProvider.equals(MySQL)) {
> MysqlConnectionPoolDataSource dsource =
> (MysqlConnectionPoolDataSource) context.lookup("mydatabase");
> pcon = dsource.getPooledConnection();
> // DB2
> } else if (dbProvider.equals(DB2)) {
> ... DB2 Statements ...
> } else {
> System.err.println("Database sconosciuto - controllare
> db.properties ");
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> return pcon;
> }
>
> private static Context createContext() throws NamingException {
> Context context = null;
> try {
> Properties env = new Properties();
> env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "com.sun.jndi.fscontext.RefFSContextFactory");
> env.setProperty(Context.PROVIDER_URL, "file:E:/JNDI/JDBC");
> context = new InitialContext(env);
> } catch (Exception e) {
> e.printStackTrace();
> } return context;
> }
>
> The resourceBundle refers to the db.properties file:
>
> # Configurazione DataBase e connessione
> # Database/connessione/Driver per MySQL
> mconnessione = jdbc:mysql://localhost:3306/
> mdatabase = mydatabase
> muser = myuser
> mpwd = mypwd
> dbprovider = MySQL
>
> To register the DataSource and access it from File System, you must obtain
> JNDI classes that support the file system, for example Sun's fscontext.jar
> (which requires providerutil.jar as well) and add these to your classpath
> (See the Java Naming and Directory Interface(TM) tutorial at
> http://java.sun.com/docs/books/tutorial/jndi/index.html).
>
> A tutorial on JDBC is here:
> http://java.sun.com/docs/books/tutorial/jdbc/TOC.html
>
>
> Hope this helps
> Riccardo Cattania
> www.riccardocattania.net
|
|
|
Re: Connect to MySql 5.0 [message #26850 is a reply to message #26460] |
Mon, 26 February 2007 00:41   |
Eclipse User |
|
|
|
Hi,
I am using Linux Fedora core4, Eclipse 3.2. and using CDT for developing
my programe and MYSQL 4.1.11 as database. I have used to establish a
connection between CDT ( C / C++) and MYSQL, I have used the following
command, and it is working. Make this programe giving this option in
right click on the project -> Properties -> C/C++ Build-> GCC C++ Linker
-> Libraries -> Library Search path ( -L ) and add the option
"/usr/X11R6/lib -lX11 -L/usr/include/mysql -L/usr/lib/mysql -lmysqlclient
" without double quorts.
create a header file named " ConnectCMYSQL.h "
#include <mysql.h>
/*This function is used for connecting the data base */
MYSQL mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int C_Connect_MYSQL( char *hostname, char *username, char *passwd, char
*dbname )
{
mysql_init(&mysql);
if(!mysql_real_connect(&mysql, hostname, username, passwd, dbname,
0, NULL, 0))
{
printf("%d: %s \n", mysql_errno(&mysql),
mysql_error(&mysql));
printf("Connection Refused by MYSQL\n");
return 1;
}
else
{
printf("Connect\n");
return 0;
}
void Exectue_Query (char *Exec_Qry)
{
if(mysql_query(&mysql, Exec_Qry))
{
fprintf(stderr, "%d: %s\n", mysql_errno(&mysql),
mysql_error(&mysql));
}
else
{
result = mysql_store_result(&mysql);
printf("Qry Execute < %s > \n", Exec_Qry);
while(row = mysql_fetch_row(result))
{
printf("%s, %s - %s \n", row[1], row[2], row[3]);
}
mysql_free_result(result);
mysql_close(&mysql);
}
}
}
Create a file main.c /main.cpp
---------------------------------
#include <X11/Xlib.h>
#include <stdio.h>
#include <ConnectCMYSQL.h> /*For MYSQL Connection */
int main(int argc, char* argv[])
{
char *Qry;
C_Connect_MYSQL("localhost","username", "password", "Database name");
/*Try to create a connection with database */
Qry = "select * from TABLENAME ;" ;
Exectue_Query(Qry);
}
|
|
|
Re: Connect to MySql 5.0 [message #31012 is a reply to message #26494] |
Fri, 25 May 2007 14:19   |
Eclipse User |
|
|
|
Originally posted by: des.oregon.nOSPamPlz.org.uk
On Sun, 11 Feb 2007 22:04:15 +0100, Riccardo Cattania
<riccardocattania@alice.it> wrote:
>Jalal ha scritto:
>> Hi,
>> Is it possible to connect to MySql 5.0, I am using eclipse 3.2.1. If yes,
>> What plug-ins Do I need to install ,and is there any tutorial on how do to
>> make the conneciton.
>> Thanks.
>>
>>
>Hi,
>I am using MySQL 5.0 with eclipse 3.2.0 and the
>mysql-connector-java-3.1.13 is in the classpath; you can find it at
>http://dev.mysql.com/downloads/ (now the
>http://dev.mysql.com/downloads/connector/j/5.0.html is available).
>
>To establish the connection I have used at first the DriverManager
>class, and now the DataSource object.
>
>DriverManager:
>
Riccardo,
Did you manage to configure Eclipse so that connections to a MySQL 5.0
server could be made from the Database Explorer view? The new
connection wizard does not seem to have am option for 5.0.
>Hope this helps
>Riccardo Cattania
>www.riccardocattania.net
--
Cheers, Des
|
|
|
Re: Connect to MySql 5.0 [message #31047 is a reply to message #31012] |
Fri, 25 May 2007 16:21  |
Eclipse User |
|
|
|
Des ha scritto:
> On Sun, 11 Feb 2007 22:04:15 +0100, Riccardo Cattania
> <riccardocattania@alice.it> wrote:
>
>> Jalal ha scritto:
>>> Hi,
>>> Is it possible to connect to MySql 5.0, I am using eclipse 3.2.1. If yes,
>>> What plug-ins Do I need to install ,and is there any tutorial on how do to
>>> make the conneciton.
>>> Thanks.
>>>
>>>
>> Hi,
>> I am using MySQL 5.0 with eclipse 3.2.0 and the
>> mysql-connector-java-3.1.13 is in the classpath; you can find it at
>> http://dev.mysql.com/downloads/ (now the
>> http://dev.mysql.com/downloads/connector/j/5.0.html is available).
>>
>> To establish the connection I have used at first the DriverManager
>> class, and now the DataSource object.
>>
>> DriverManager:
>>
>
> Riccardo,
>
> Did you manage to configure Eclipse so that connections to a MySQL 5.0
> server could be made from the Database Explorer view? The new
> connection wizard does not seem to have am option for 5.0.
>
>> Hope this helps
>> Riccardo Cattania
>> www.riccardocattania.net
No,
I have used the MySql 4.1 option from the connection wizard: it works
for the MySQL 5.0 server too.
Riccardo
|
|
|
Re: Connect to MySql 5.0 [message #584373 is a reply to message #26460] |
Sun, 11 February 2007 16:04  |
Eclipse User |
|
|
|
Jalal ha scritto:
> Hi,
> Is it possible to connect to MySql 5.0, I am using eclipse 3.2.1. If yes,
> What plug-ins Do I need to install ,and is there any tutorial on how do to
> make the conneciton.
> Thanks.
>
>
Hi,
I am using MySQL 5.0 with eclipse 3.2.0 and the
mysql-connector-java-3.1.13 is in the classpath; you can find it at
http://dev.mysql.com/downloads/ (now the
http://dev.mysql.com/downloads/connector/j/5.0.html is available).
To establish the connection I have used at first the DriverManager
class, and now the DataSource object.
DriverManager:
public static Connection creaConnessione()
{
try {
if (resourceBundle == null) {
try {
resourceBundle = ResourceBundle.getBundle("db");
} catch (Exception e) {
visualizzaErrore();
}
}
dbProvider = getDbProvider();
// postgreSQL
if (dbProvider.equals(postgreSQL)) {
..... posgreSQL Statements....
} else if (dbProvider.equals(MySQL)) {
DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
String connessione = resourceBundle.getString("mconnessione");
String database = resourceBundle.getString("mdatabase");
String user = resourceBundle.getString("muser");
String pwd = resourceBundle.getString("mpwd");
con = DriverManager.getConnection(connessione + database,
user, pwd);
// DB2
} else if (dbProvider.equals(DB2)) {
... DB2 Statements ...
// Sconosciuto
} else {
System.err.println("Database sconosciuto - controllare
db.properties ");
}
return con;
} catch(java.sql.SQLException e) {
System.err.print("Connessione database non riuscita: ");
System.err.println(e.getMessage());
}
return null;
}
public static String getDbProvider() {
if (resourceBundle == null) {
try {
resourceBundle = ResourceBundle.getBundle("db");
} catch (Exception e) {
visualizzaErrore();
}
}
return resourceBundle.getString("dbprovider");
}
Now I use a DataSource object to establish a PooledConnection; I have
registered the MysqlConnectionPoolDataSource in the File System, and
this is the code to establish the connection:
/**
* Crea la connessione con il database tramite una Data Source
*
*/
public static Connection creaPoolConn()
{
if (pcon == null) {
pcon = creaPCon();
}
try {
con = pcon.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
/**
* Crea la PooledConnection
*
*/
public static PooledConnection creaPCon()
{
dbProvider = getDbProvider();
try {
Context context = createContext();
// MySQL
if (dbProvider.equals(MySQL)) {
MysqlConnectionPoolDataSource dsource =
(MysqlConnectionPoolDataSource) context.lookup("mydatabase");
pcon = dsource.getPooledConnection();
// DB2
} else if (dbProvider.equals(DB2)) {
... DB2 Statements ...
} else {
System.err.println("Database sconosciuto -
controllare db.properties ");
}
} catch (Exception e) {
e.printStackTrace();
}
return pcon;
}
private static Context createContext() throws NamingException {
Context context = null;
try {
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.setProperty(Context.PROVIDER_URL, "file:E:/JNDI/JDBC");
context = new InitialContext(env);
} catch (Exception e) {
e.printStackTrace();
}
return context;
}
The resourceBundle refers to the db.properties file:
# Configurazione DataBase e connessione
# Database/connessione/Driver per MySQL
mconnessione = jdbc:mysql://localhost:3306/
mdatabase = mydatabase
muser = myuser
mpwd = mypwd
dbprovider = MySQL
To register the DataSource and access it from File System, you must
obtain JNDI classes that support the file system, for example Sun's
fscontext.jar (which requires providerutil.jar as well) and add these to
your classpath (See the Java Naming and Directory Interface(TM) tutorial
at http://java.sun.com/docs/books/tutorial/jndi/index.html).
A tutorial on JDBC is here:
http://java.sun.com/docs/books/tutorial/jdbc/TOC.html
Hope this helps
Riccardo Cattania
www.riccardocattania.net
|
|
|
Re: Connect to MySql 5.0 [message #584389 is a reply to message #26494] |
Sun, 11 February 2007 17:50  |
Eclipse User |
|
|
|
Originally posted by: alnoor20000.yahoo.co.uk
Thanks alot, that is really helpful.
"Riccardo Cattania" <riccardocattania@alice.it> wrote in message
news:eqo0ca$uk9$1@utils.eclipse.org...
> Jalal ha scritto:
>> Hi,
>> Is it possible to connect to MySql 5.0, I am using eclipse 3.2.1. If yes,
>> What plug-ins Do I need to install ,and is there any tutorial on how do
>> to make the conneciton.
>> Thanks.
> Hi,
> I am using MySQL 5.0 with eclipse 3.2.0 and the
> mysql-connector-java-3.1.13 is in the classpath; you can find it at
> http://dev.mysql.com/downloads/ (now the
> http://dev.mysql.com/downloads/connector/j/5.0.html is available).
>
> To establish the connection I have used at first the DriverManager class,
> and now the DataSource object.
>
> DriverManager:
>
> public static Connection creaConnessione()
> {
> try {
> if (resourceBundle == null) {
> try {
> resourceBundle = ResourceBundle.getBundle("db");
> } catch (Exception e) {
> visualizzaErrore();
> }
> }
> dbProvider = getDbProvider();
> // postgreSQL
> if (dbProvider.equals(postgreSQL)) {
> ..... posgreSQL Statements....
> } else if (dbProvider.equals(MySQL)) {
> DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
> String connessione = resourceBundle.getString("mconnessione");
> String database = resourceBundle.getString("mdatabase");
> String user = resourceBundle.getString("muser");
> String pwd = resourceBundle.getString("mpwd");
> con = DriverManager.getConnection(connessione + database, user,
> pwd);
> // DB2 } else if (dbProvider.equals(DB2)) {
> ... DB2 Statements ...
> // Sconosciuto
> } else {
> System.err.println("Database sconosciuto - controllare
> db.properties ");
> }
> return con;
> } catch(java.sql.SQLException e) {
> System.err.print("Connessione database non riuscita: ");
> System.err.println(e.getMessage());
> }
> return null; }
> public static String getDbProvider() {
> if (resourceBundle == null) {
> try {
> resourceBundle = ResourceBundle.getBundle("db");
> } catch (Exception e) {
> visualizzaErrore();
> }
> }
> return resourceBundle.getString("dbprovider");
> }
>
>
> Now I use a DataSource object to establish a PooledConnection; I have
> registered the MysqlConnectionPoolDataSource in the File System, and this
> is the code to establish the connection:
>
> /**
> * Crea la connessione con il database tramite una Data Source
> *
> */
> public static Connection creaPoolConn()
> {
> if (pcon == null) {
> pcon = creaPCon();
> }
> try {
> con = pcon.getConnection();
> } catch (SQLException e) {
> e.printStackTrace();
> }
> return con;
> }
> /**
> * Crea la PooledConnection
> *
> */
>
> public static PooledConnection creaPCon()
> {
> dbProvider = getDbProvider();
> try {
> Context context = createContext();
> // MySQL
> if (dbProvider.equals(MySQL)) {
> MysqlConnectionPoolDataSource dsource =
> (MysqlConnectionPoolDataSource) context.lookup("mydatabase");
> pcon = dsource.getPooledConnection();
> // DB2
> } else if (dbProvider.equals(DB2)) {
> ... DB2 Statements ...
> } else {
> System.err.println("Database sconosciuto - controllare
> db.properties ");
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> return pcon;
> }
>
> private static Context createContext() throws NamingException {
> Context context = null;
> try {
> Properties env = new Properties();
> env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "com.sun.jndi.fscontext.RefFSContextFactory");
> env.setProperty(Context.PROVIDER_URL, "file:E:/JNDI/JDBC");
> context = new InitialContext(env);
> } catch (Exception e) {
> e.printStackTrace();
> } return context;
> }
>
> The resourceBundle refers to the db.properties file:
>
> # Configurazione DataBase e connessione
> # Database/connessione/Driver per MySQL
> mconnessione = jdbc:mysql://localhost:3306/
> mdatabase = mydatabase
> muser = myuser
> mpwd = mypwd
> dbprovider = MySQL
>
> To register the DataSource and access it from File System, you must obtain
> JNDI classes that support the file system, for example Sun's fscontext.jar
> (which requires providerutil.jar as well) and add these to your classpath
> (See the Java Naming and Directory Interface(TM) tutorial at
> http://java.sun.com/docs/books/tutorial/jndi/index.html).
>
> A tutorial on JDBC is here:
> http://java.sun.com/docs/books/tutorial/jdbc/TOC.html
>
>
> Hope this helps
> Riccardo Cattania
> www.riccardocattania.net
|
|
|
Re: Connect to MySql 5.0 [message #584526 is a reply to message #26460] |
Mon, 26 February 2007 00:41  |
Eclipse User |
|
|
|
Hi,
I am using Linux Fedora core4, Eclipse 3.2. and using CDT for developing
my programe and MYSQL 4.1.11 as database. I have used to establish a
connection between CDT ( C / C++) and MYSQL, I have used the following
command, and it is working. Make this programe giving this option in
right click on the project -> Properties -> C/C++ Build-> GCC C++ Linker
-> Libraries -> Library Search path ( -L ) and add the option
"/usr/X11R6/lib -lX11 -L/usr/include/mysql -L/usr/lib/mysql -lmysqlclient
" without double quorts.
create a header file named " ConnectCMYSQL.h "
#include <mysql.h>
/*This function is used for connecting the data base */
MYSQL mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int C_Connect_MYSQL( char *hostname, char *username, char *passwd, char
*dbname )
{
mysql_init(&mysql);
if(!mysql_real_connect(&mysql, hostname, username, passwd, dbname,
0, NULL, 0))
{
printf("%d: %s \n", mysql_errno(&mysql),
mysql_error(&mysql));
printf("Connection Refused by MYSQL\n");
return 1;
}
else
{
printf("Connect\n");
return 0;
}
void Exectue_Query (char *Exec_Qry)
{
if(mysql_query(&mysql, Exec_Qry))
{
fprintf(stderr, "%d: %s\n", mysql_errno(&mysql),
mysql_error(&mysql));
}
else
{
result = mysql_store_result(&mysql);
printf("Qry Execute < %s > \n", Exec_Qry);
while(row = mysql_fetch_row(result))
{
printf("%s, %s - %s \n", row[1], row[2], row[3]);
}
mysql_free_result(result);
mysql_close(&mysql);
}
}
}
Create a file main.c /main.cpp
---------------------------------
#include <X11/Xlib.h>
#include <stdio.h>
#include <ConnectCMYSQL.h> /*For MYSQL Connection */
int main(int argc, char* argv[])
{
char *Qry;
C_Connect_MYSQL("localhost","username", "password", "Database name");
/*Try to create a connection with database */
Qry = "select * from TABLENAME ;" ;
Exectue_Query(Qry);
}
|
|
|
Re: Connect to MySql 5.0 [message #585749 is a reply to message #26494] |
Fri, 25 May 2007 14:19  |
Eclipse User |
|
|
|
Originally posted by: des.oregon.nOSPamPlz.org.uk
On Sun, 11 Feb 2007 22:04:15 +0100, Riccardo Cattania
<riccardocattania@alice.it> wrote:
>Jalal ha scritto:
>> Hi,
>> Is it possible to connect to MySql 5.0, I am using eclipse 3.2.1. If yes,
>> What plug-ins Do I need to install ,and is there any tutorial on how do to
>> make the conneciton.
>> Thanks.
>>
>>
>Hi,
>I am using MySQL 5.0 with eclipse 3.2.0 and the
>mysql-connector-java-3.1.13 is in the classpath; you can find it at
>http://dev.mysql.com/downloads/ (now the
>http://dev.mysql.com/downloads/connector/j/5.0.html is available).
>
>To establish the connection I have used at first the DriverManager
>class, and now the DataSource object.
>
>DriverManager:
>
Riccardo,
Did you manage to configure Eclipse so that connections to a MySQL 5.0
server could be made from the Database Explorer view? The new
connection wizard does not seem to have am option for 5.0.
>Hope this helps
>Riccardo Cattania
>www.riccardocattania.net
--
Cheers, Des
|
|
|
Re: Connect to MySql 5.0 [message #585756 is a reply to message #31012] |
Fri, 25 May 2007 16:21  |
Eclipse User |
|
|
|
Des ha scritto:
> On Sun, 11 Feb 2007 22:04:15 +0100, Riccardo Cattania
> <riccardocattania@alice.it> wrote:
>
>> Jalal ha scritto:
>>> Hi,
>>> Is it possible to connect to MySql 5.0, I am using eclipse 3.2.1. If yes,
>>> What plug-ins Do I need to install ,and is there any tutorial on how do to
>>> make the conneciton.
>>> Thanks.
>>>
>>>
>> Hi,
>> I am using MySQL 5.0 with eclipse 3.2.0 and the
>> mysql-connector-java-3.1.13 is in the classpath; you can find it at
>> http://dev.mysql.com/downloads/ (now the
>> http://dev.mysql.com/downloads/connector/j/5.0.html is available).
>>
>> To establish the connection I have used at first the DriverManager
>> class, and now the DataSource object.
>>
>> DriverManager:
>>
>
> Riccardo,
>
> Did you manage to configure Eclipse so that connections to a MySQL 5.0
> server could be made from the Database Explorer view? The new
> connection wizard does not seem to have am option for 5.0.
>
>> Hope this helps
>> Riccardo Cattania
>> www.riccardocattania.net
No,
I have used the MySql 4.1 option from the connection wizard: it works
for the MySQL 5.0 server too.
Riccardo
|
|
|
Goto Forum:
Current Time: Mon May 05 06:19:30 EDT 2025
Powered by FUDForum. Page generated in 0.07955 seconds
|