The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > Database


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content 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 us.
Tags:

Closed Thread
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 06-10-2007, 05:20 PM
Oliver D4
Posts: n/a
[SOLVED] How do you connect java programming to a MySQL database?

So how do you connect it? can anyone generate a statement line as in like:
jdbc.mysql:\localhost\dbase?user&pass?
where do you post the port number? the database name? what is the correct arrangement? what is the driver name? is there a certain class file you need in order to use the driver? If there is, where can I get it?

Sorry for a lot of questions. THanks.

Our project goes this way:
Equipment Inventory and Tracking Application.
User can search by date, time, borrower. Can generate a statistics of equip frequently used, borrowed. Can generate search equip status life: damage, repaired, etc.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #2 (permalink)  
Old 06-10-2007, 05:20 PM
fang
Posts: n/a
you should have a function something like this:

public static Connection getConnection() throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver"); //specifiy the driver
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testing","root","");// refer below for more details
} catch (ClassNotFoundException e) {
System.err.println(e);
throw new SQLException (e.toString());
} catch (SQLException e) {
System.err.println(e);
throw e;
}
return con;
}

jdbc:mysql://localhost:3306/testing","root","pwd"

localhost: ur server
3306: mysql port number
testing: database name
root: username to mysql
pwd: password to mysql

for the downloading of driver, u can go google search: "mysql driver", and download it. bcos i have where i gotten it.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #3 (permalink)  
Old 06-10-2007, 05:21 PM
ToT
Posts: n/a
first of all use MySQL Query Browser to deal visualy with ur DB
to connect mySQL with java u need the following jar file

mysql-connector-java-5.0.4-bin.jar

u can find it on mySQL website
add it to ur project library
and here is the code for connecting java with mySQL compile and run it after adding the jar file

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Test {

public Connection getConn() throws SQLException, ClassNotFoundException{

Class.forName("com.mysql.jdbc....
Connection conn = DriverManager.getConnection("j...
return conn;
}
public Test(){
try {
getConn();
System.out.println("Connection is "+getConn());
} catch (SQLException e) {

e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Test tt = new Test();
}
}

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Closed Thread


Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 07:07 AM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50