File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments