1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import org.h2.jdbcx.JdbcDataSource;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
try
{
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:/test");
ds.setUser("sa");
ds.setPassword("sa");
Connection conn = ds.getConnection();
Statement st=ds.getConnection().createStatement();
boolean b=st.execute("create table test (nom varchar, prenom varchar);");
if (b)
System.out.println("creation reussie");
else
{
System.out.println("creation non reussie");
return;
}
b=st.execute("insert into test values ('nabster', 'inc');");
ResultSet rs=st.executeQuery("select * from test");
while(rs.next())
{
System.out.println(rs.getString("nom"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
} |
Partager