.


:




:

































 

 

 

 





, 2.1 , :

import java.sql.*;

import java.io.*;

public class ddb {

public static void main(String args[]) {

Connection connection = null;

try {

//

String driverName = "com.mysql.jdbc.Driver";

Class. forName (driverName);

//

String serverName = "localhost";

String mydatabase = "my";

String url = "jdbc:mysql://" + serverName + "/"

+ mydatabase;

String username = "root";

String password = "root";

//

connection = DriverManager. getConnection (url, username, password);

System. out. println("is connect to DB" + " "

+ connection);

Statement stmt = connection.createStatement();

//

int qucols = "SHOW COLUMNS FROM zoo";

ResultSet cols = stmt.executeUpdate(qucols);

//

String query = "Select * FROM zoo";

//

ResultSet rs = stmt.executeQuery(query);

String dbrecord = "";

//

while (rs.next())

{

for(i = 1; i<=cols; i++)

dbRecord += rs.getString(i) + " \t ";

System. out. println(dbRecord); //

dbRecord = "";

} //

connection.close(); //

} // try

//

catch (ClassNotFoundException e) {

e.printStackTrace();

//

} catch (SQLException e) {

e.printStackTrace();

//

}

}

}

MySQL, , my zoo, .

;

is connect to DBcom.mysql.jdbc.JDBC4Connection@1f7c9157

bear Misha 11 m

lion Chezar 5 m

wolf Horatio 12 m

elephant Peter 10 m


III.

- .

MySQL ( I ).

.

.

25 .

Java, Eclipse. . . , main().

, :

1. , main() .

2. , :

:

1. .

2. .

3. .

4. .

5. ( ).

6. .

7. .


 

IV. ( )

1. -.

2. .

3. .

4. .

5. .

6. .

7. .

8. ( ).

9. .

10. .

11. .

12. .

13. ( ).

14. .

15. .

16. Call-.

17. .

18. .

19. ( ).

20. ( ).

21. .

22. .

23. .

24. .

25. .


 

1. .., .. Java. CX-310-035, 2- . / . .: -, 2006. - 688 .

2. . Thinking In Java Enterprise ( ): http://javatutor.net/books/tiej

3. Java : http://cruxastata.euro.ru/node8.htm

4. : http://kek.ksu.ru/EOS/Java/gl4_5.html





:


: 2018-11-10; !; : 362 |


:

:

- - , .
==> ...

1894 - | 1845 -


© 2015-2024 lektsii.org - -

: 0.01 .