-
Notifications
You must be signed in to change notification settings - Fork 3
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
2 changed files
with
45 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
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,40 @@ | ||
/** | ||
* | ||
*/ | ||
package com.taobao.fario.server.db; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.sql.*; | ||
|
||
/** | ||
* @author taichan | ||
* | ||
*/ | ||
public class test { | ||
public static void main(String[] args) throws Exception { | ||
|
||
Connection connection = getConnection(); | ||
|
||
Statement stmt = connection.createStatement(); | ||
stmt.executeUpdate("DROP TABLE IF EXISTS ticks"); | ||
stmt.executeUpdate("CREATE TABLE ticks (tick timestamp)"); | ||
stmt.executeUpdate("INSERT INTO ticks VALUES (now())"); | ||
ResultSet rs = stmt.executeQuery("SELECT name FROM \"user\""); | ||
while (rs.next()) { | ||
System.out.println("Read from DB: " + rs.getString("name")); | ||
} | ||
} | ||
|
||
private static Connection getConnection() throws URISyntaxException, | ||
SQLException { | ||
URI dbUri = new URI( | ||
"postgres://postgres:lee@localhost:5432/fario"); | ||
|
||
String username = dbUri.getUserInfo().split(":")[0]; | ||
String password = dbUri.getUserInfo().split(":")[1]; | ||
String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + dbUri.getPath(); | ||
|
||
return DriverManager.getConnection(dbUrl, username, password); | ||
} | ||
} |