Hello, members of the forum.

I study java, decided to take up the database. I developed a theory, climbed the net and realized that I was at a dead end ... If anyone had free time, he would be very grateful for the help in solving the following questions.

  1. How to prepare for work environment development environment Eclipse. I downloaded the mysql-5.5.21-win32 server and the mysql-connector-java-5.1.18 driver, but I don’t understand what to do with them further.
  2. All Internet resources describe how to log into the database and send requests to it. But I do not understand how (with the help of which code and libraries) you can create databases and tables in them, or how you can make it so that the program can add new tables of a certain structure to the database.
  3. You can make it so that transferring the folder with the program (where the database driver and server will also be) on the Windows OS (with the java-machine installed) is enough for the program and database to function correctly, in other words, the user has a minimum of settings - reset flash drive and enjoy.

If someone has a free minute - I will be very grateful.

    3 answers 3

    install mysql-5.5.21-win32 as a Windows application. This is your server that will manage one / several (how many will be created in general) database. mysql-connector-java-5.1.18 is your library for executing database queries. It needs to be connected to the Eclipse project like any other library. To "create databases and tables in them," take a graphical application. MySQL client under Win. One of the most convenient HeidiSQL (freeware, portable).

    There is nothing special to study in pure JDBC, it’s just a connection driver and database queries. You need SQL and administration skills. While you do not even distinguish the client from the server. A good course on the theory of database here .

      1) Look at the set of screencasts on youtube - quite clearly.

      2) JDBC is not designed for good work with the database, although of course there are programs that offer a GUI for working with JDBC through JDBC. In the same Eclipse using the plugin, you can pick up and in GUI mode, type data and so on. Unfortunately, I don’t really like Eclipse, but in Netbeans, in Intellij, this is easy and simple, yes. If you mean adding data programmatically, then there is no problem with JDBC. Look at PreparedStatement and Statement.executeUpdate()

      3) Well, as for muscle, I’m not sure that this can be done - all the same, some settings from the machine to the machine will have to be changed (at least the server address). But to take some kind of embedded database is easy and natural - say, Derby or Hypersonic SQL - they are intended for just such pieces.

        I was advised to familiar with this approach: MyEclipse development environment and I understand how to use Microsoft dBase Driver (*. dbf) (and do not need to deliver anything to Windows?)

         String url= "jdbc:odbc:Driver={Microsoft dBase Driver (*.dbf)};DBQ="+System.getProperty("user.dir"); Connection con; Statement st; ResultSet rs; public void Con(){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection(url); st = con.createStatement(); }catch (Exception e) {System.out.println(e);} } fCrtCnf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try{ st.executeUpdate("create table "+fCrtNam.getText()+"(Kod integer, q varchar(100), one varchar(100), two varchar(100), three varchar(100), four varchar(100), t integer, img varchar(100));"); }catch (Exception ex) {System.out.println(ex);} fFrmCrt.setVisible(false); } }); 

        then you can use st.executeUpdate ("create table ..... to create a table

        or based on the string Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); folder C: Program Files Sun need to deliver to Windows, or is it not used? Is this a database server? if so what needs to be delivered to the OS? What are the pros and cons of this approach?