Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > MySQL Connector/J

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-31-03, 04:48
blackie blackie is offline
Registered User
 
Join Date: Mar 2003
Posts: 2
MySQL Connector/J

how do i connection MySQL using MySQL Connector/J in Java?
Reply With Quote
  #2 (permalink)  
Old 03-31-03, 13:08
omiossec omiossec is offline
Registered User
 
Join Date: Jan 2003
Location: Paris, France
Posts: 320
Re: MySQL Connector/J

Quote:
Originally posted by blackie
how do i connection MySQL using MySQL Connector/J in Java?


what do you need

how to create a connection ?

how to install the driver ?
__________________
Olivier Miossec
--
http://www.lasso-developpeur.net/
--
Reply With Quote
  #3 (permalink)  
Old 04-01-03, 07:36
blackie blackie is offline
Registered User
 
Join Date: Mar 2003
Posts: 2
Re: MySQL Connector/J

Quote:
Originally posted by omiossec
what do you need

how to create a connection ?

how to install the driver ?


i need to know how is it been used in a sense the String used to connect the MySQL...
Reply With Quote
  #4 (permalink)  
Old 04-05-03, 17:03
zenpizza zenpizza is offline
Registered User
 
Join Date: Apr 2003
Location: New York City
Posts: 2
Re: MySQL Connector/J

Quote:
Originally posted by blackie
i need to know how is it been used in a sense the String used to connect the MySQL...


I just fought with this for awhile.
Give this sample code a try:

import java.sql.*;
import java.util.*;

public class CheckDriverManager {

public static void main(String[] args) {
String driverName = "com.mysql.jdbc.Driver";
Connection conn = null;

//Put in your databasename here
String databaseURL = "jdbc:mysql://localhost/databasename";

//Put in your username and password here
String username = "someuser";
String password = "somepassword";

// Verify that the driver class exists.
try {
Class.forName(driverName);
System.out.println("Did Class.forName()"); //LOGGER
} catch (Exception e) {
e.printStackTrace();
System.out.println("Driver could not be found.");
}

// Get a connection.
try {
conn = DriverManager.getConnection(databaseURL, username, password);
System.out.println("Did getConnection()"); //LOGGER

Statement stat = conn.createStatement();

//Put in your own table name here.
ResultSet result = stat.executeQuery("SELECT * FROM tablename");
result.next();
System.out.println(result.getString(1));

stat.close();
conn.close();

} catch (SQLException sqle) {
sqle.printStackTrace();
System.out.println("Could not get connection."); //LOGGER
}
}
}
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On