![]() |
|
|
|
| ||||||
|
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: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [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. |
| |
| |||
| 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. |
| |||
| 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(); } } |
![]() |
| Thread Tools | |
| Display Modes | |
| |