Skip to content

Commit ce1ec51

Browse files
authored
Create JDBCExample3.java
1 parent 6c17393 commit ce1ec51

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

JDBCExample3.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Demonstrating Create Table function in Java JDBC
2+
import java.sql.Connection;
3+
import java.sql.DriverManager;
4+
import java.sql.SQLException;
5+
import java.sql.Statement;
6+
7+
public class JDBCExample3 {
8+
static final String DB_URL = "jdbc:mysql://localhost/TUTORIALSPOINT";
9+
static final String USER = "guest";
10+
static final String PASS = "guest123";
11+
12+
public static void main(String[] args) {
13+
// Open a connection
14+
try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
15+
Statement stmt = conn.createStatement();
16+
) {
17+
String sql = "CREATE TABLE REGISTRATION " +
18+
"(id INTEGER not NULL, " +
19+
" first VARCHAR(255), " +
20+
" last VARCHAR(255), " +
21+
" age INTEGER, " +
22+
" PRIMARY KEY ( id ))";
23+
24+
stmt.executeUpdate(sql);
25+
System.out.println("Created table in given database...");
26+
} catch (SQLException e) {
27+
e.printStackTrace();
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)