Combining Java with SQL?

This is not a code issue at once, but it definitely confuses me.

Basically, my lecturer told me that we have a project in the next semester, which includes the use of Java and SQL, intertwined.

I had no idea that language unification was even possible!

So my mind really was blown away.

I was looking for examples of such code, but no luck. So I thought I would ask you guys.

I think that the most logical thing that I should do, since I have no experience in joining, would be to create tables in SQL too because of its use in databases too and calling them through Java.

Can someone explain to me how this is possible, or just the essence of how languages ​​are combined.

+5
source share
6 answers

What you are likely to do is use JDBC to allow Java to connect to SQL databases. There are also save layers, such as Hibernate , which you can use to store and retrieve data in a database using Java.

I think the JDBC tutorials should be enough to get you started. Just don't go too far on the head too soon. Take your time and ask questions as they arise.

+14
source
  • Database Connection
  • Do something interesting with him

: http://java.sun.com/docs/books/tutorial/jdbc/index.html
, , , :

//connect to the database
Connection con = DriverManager.getConnection("jdbc:myDriver:wombat","myLogin","myPassword");  
Statement stmt = con.createStatement();
//here is the query you will execute
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
while (rs.next()) {
    //rs contains the result of the query
    //with getters you can obtain column values
    int x = rs.getInt("a");
    String s = rs.getString("b");
    float f = rs.getFloat("c");
}

, , ORM, , , JDBC .

+5

API Java JDBC.

. Sun Java: JDBC.

+3

, . .

JDBC ( Java) Java Sun Java doc JDBC

: " SQL - java".

, - . , . C. - " "

+2
+2
source

Look on the Internet for "embedded SQL." Then you will see that this subject is quite common. You will also see that SQL can be combined with many languages ​​(e.g. Python).

Note that additional layers (e.g. java class library like SQLJ) may require slightly different syntax. My advice is to start with simple SQL over JDBC.

0
source

All Articles