How to form connection between HSQLDB and C# .net ? I have already looked at SharpHSQL and H2Sharp but not able to connect the HSQLDB.
try like this: Make sure you've already add hsqldb.dll, IKVM.OpenJDK.Core.dll, IKVM.OpenJDK.Jdbc.dll as reference. If you don't have the IKVM library, you can download here.
At your C#:
using java.sql; //add this.
for create a connection:
private Connection GetConnection()
{
DriverManager.registerDriver(new org.hsqldb.jdbcDriver());
Connection conn = DriverManager.getConnection("jdbc:hsqldb:hsql://[host]/[db name]", "[username]", "[password]");
return conn;
}
how to use it:
public void LoadSetting(String userId)
{
Connection conn = null;
try
{
//Connect it!
conn = GetConnection();
string query = "SELECT A.* FROM table A";
PreparedStatement ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery();
while (rs.next())
{
//Get Query Result
Console.WriteLn(rs.getString("COL1"));
Console.WriteLn(rs.getString("COL2"));
}
}
//Close the Connection
finally
{
if (conn != null && !conn.isClosed())
{
conn.close();
conn = null;
}
}
}
Hope this help.
Cheers...