Skip to content

Commit d874ffa

Browse files
authored
Create TryWithResources_Example.java
1 parent 88b40d7 commit d874ffa

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.sql.Connection;
2+
import java.sql.DriverManager;
3+
import java.sql.ResultSet;
4+
import java.sql.SQLException;
5+
import java.sql.Statement;
6+
public class TryWithResources_Example {
7+
public static void main(String args[]) {
8+
//Getting the connection
9+
String mysqlUrl = "jdbc:mysql://localhost/mydatabase";
10+
System.out.println("Connection established......");
11+
//Registering the Driver
12+
Connection con;
13+
try{
14+
con = DriverManager.getConnection(mysqlUrl, "root", "password");
15+
Statement stmt = con.createStatement(); {
16+
}} catch (SQLException e) {
17+
e.printStackTrace();
18+
}
19+
}

0 commit comments

Comments
 (0)