Работа с базой данных H2 из C# ⇐ C#
-
Anonymous
Работа с базой данных H2 из C#
I am able to connect to H2 database from my C# application with the help of below mentioned URL
http://www.h2database.com/html/advanced ... ft_dot_net
org.h2.Driver.load(); Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "sa"); Statement stat = conn.createStatement(); //Working ResultSet rs = stat.executeQuery("SELECT 'Hello World'"); while (rs.next()) { Console.WriteLine(rs.getString(1)); } //Not Working ResultSet rs1 = stat.executeQuery("SELECT * FROM TEST"); while (rs1.next()) { Console.WriteLine(rs1.getString(1)); } I have changed the code "SELECT 'Hello World'" to "SELECT * FROM TEST" where "TEST" is the table name. I am getting table not found error. But the table is present in H2 database.
EDIT @ Nick Bull- Thank you so much for your help. Due to some reason the table created in "H2 console" is not accessible through c# code. I have tried with your logic, creating the table from C# code, it worked!!. But it is not showing in H2 console.
One more thing, "executeQuery" did not work for me to create the new table, I used "executeUpdate" (for someone it may help)
Источник: https://stackoverflow.com/questions/387 ... om-c-sharp
I am able to connect to H2 database from my C# application with the help of below mentioned URL
http://www.h2database.com/html/advanced ... ft_dot_net
org.h2.Driver.load(); Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "sa"); Statement stat = conn.createStatement(); //Working ResultSet rs = stat.executeQuery("SELECT 'Hello World'"); while (rs.next()) { Console.WriteLine(rs.getString(1)); } //Not Working ResultSet rs1 = stat.executeQuery("SELECT * FROM TEST"); while (rs1.next()) { Console.WriteLine(rs1.getString(1)); } I have changed the code "SELECT 'Hello World'" to "SELECT * FROM TEST" where "TEST" is the table name. I am getting table not found error. But the table is present in H2 database.
EDIT @ Nick Bull- Thank you so much for your help. Due to some reason the table created in "H2 console" is not accessible through c# code. I have tried with your logic, creating the table from C# code, it worked!!. But it is not showing in H2 console.
One more thing, "executeQuery" did not work for me to create the new table, I used "executeUpdate" (for someone it may help)
Источник: https://stackoverflow.com/questions/387 ... om-c-sharp
Мобильная версия