-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package connectsql; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
|
||
|
||
public class Connect { | ||
|
||
public Connection getConnection() { | ||
Connection conn = null; | ||
try{ | ||
String userName = "root"; | ||
String password = ""; | ||
String DatabaseName = "test"; | ||
String url = "jdbc:mysql://localhost/" + DatabaseName; | ||
Class.forName ("com.mysql.jdbc.Driver"); | ||
conn = DriverManager.getConnection(url, userName, password); | ||
System.out.println("Ok"); | ||
} catch (Exception e) { | ||
// TODO: handle exception | ||
e.printStackTrace(); | ||
} | ||
return conn; | ||
} | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
Connection conn = null; | ||
try{ | ||
//cmt | ||
String userName = "root"; | ||
String password = ""; | ||
String DatabaseName = "test"; | ||
String url = "jdbc:mysql://localhost/" + DatabaseName; | ||
Class.forName ("com.mysql.jdbc.Driver"); | ||
conn = DriverManager.getConnection(url, userName, password); | ||
System.out.println("Ok"); | ||
|
||
|
||
// String sql = "SELECT * FROM table21da"; | ||
// PreparedStatement stm = conn.prepareStatement(sql); | ||
// ResultSet rs = stm.executeQuery(); | ||
// while(rs.next()) { | ||
// System.out.println(rs.getInt(1) + "\t" + rs.getString(2)); | ||
// } | ||
// | ||
// | ||
// | ||
// sql = "INSERT INTO table21da(ID, Name) VALUES (913, 'SJDFJDSJFSDJ')"; | ||
// stm = conn.prepareStatement(sql); | ||
// stm.execute(); | ||
// | ||
// sql = "INSERT INTO table21da(ID, Name) VALUES (897, 'alophuday')"; | ||
// stm = conn.prepareStatement(sql); | ||
// stm.execute(); | ||
|
||
} catch (Exception e) { | ||
// TODO: handle exception | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |