Skip to content

Commit 87e1339

Browse files
authored
Create JDBCExample1.java
1 parent 830f3ce commit 87e1339

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

JDBCExample1.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Demonstarting Select Database
2+
import java.sql.Connection;
3+
import java.sql.DriverManager;
4+
import java.sql.SQLException;
5+
import java.sql.Statement;
6+
7+
public class JDBCExample1 {
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+
System.out.println("Connecting to a selected database...");
14+
// Open a connection
15+
try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);) {
16+
System.out.println("Connected database successfully...");
17+
} catch (SQLException e) {
18+
e.printStackTrace();
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)