mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 03:51:58 -08:00
Initial sqlite support.
This commit is contained in:
parent
e901343aad
commit
20402f1cad
8 changed files with 68 additions and 0 deletions
35
Mage.Common/src/mage/db/EntityManager.java
Normal file
35
Mage.Common/src/mage/db/EntityManager.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package mage.db;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public class EntityManager {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
Connection conn = DriverManager.getConnection("jdbc:sqlite:mage.db");
|
||||
Statement stat = conn.createStatement();
|
||||
stat.executeUpdate("drop table if exists users;");
|
||||
stat.executeUpdate("create table users (login, password);");
|
||||
|
||||
PreparedStatement prep = conn.prepareStatement("insert into users values (?, ?);");
|
||||
|
||||
prep.setString(1, "TestUser");
|
||||
prep.setString(2, "123");
|
||||
prep.execute();
|
||||
|
||||
prep.setString(1, "TestUser2");
|
||||
prep.setString(2, "12345");
|
||||
prep.execute();
|
||||
|
||||
ResultSet rs = stat.executeQuery("select * from users;");
|
||||
while (rs.next()) {
|
||||
System.out.println("user = " + rs.getString("login"));
|
||||
System.out.println("password = " + rs.getString("password"));
|
||||
}
|
||||
rs.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
11
Mage.Common/src/mage/db/model/User.java
Normal file
11
Mage.Common/src/mage/db/model/User.java
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package mage.db.model;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public class User {
|
||||
|
||||
private String login;
|
||||
|
||||
private String password;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue