como faço de fato para configurar um banco h2, a um jar, para funcionar tudo junto com banco e projeto…??
estou pesquisando mais com dúvidas, qualquer luz é bem vinda.
olhei este tópico mas tive problemas…
http://www.guj.com.br/java/257609-off-topic-iniciando-o-h2-db-pela-aplicacao-j2se#1611763
nestas linhas
try {
Server s = Server.createTcpServer(new String[]{"-tcp","-tcpAllowOthers","-tcpPort","9001","-trace"}); //aqui crio e defino o servidor TCP com seus parametros
s.start(); //inicia o servidor
ele não consegue usar este metodo .createTcpServer
quero um banco local talvez nao precise disso… … do TCP no caso. ou Server… estou tentando sem … mas nao deu…
[code]
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package h2databasetestes;
import com.sun.corba.se.spi.activation.Server;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class Conexao {
public static Connection getConnection() throws SQLException{
try {
Class.forName(“org.h2.Driver”); //driver para h2 db
return DriverManager.getConnection(“jdbc:h2:~/test/localhost:8082/TEST/”,“SA”,""); //retorna conexao h2 db
}catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
throw new SQLException();
}
}
public static void main(String[] args){
//inicia o servidor e testa a conexao tcp com h2 db
try {
// Server s = Server.createTcpServer(new String[]{"-tcp","-tcpAllowOthers","-tcpPort",“9001”,"-trace"}); //aqui crio e defino o servidor TCP com seus parametros
// s.start(); //inicia o servidor
Connection con = Conexao.getConnection();
PreparedStatement stm = con.prepareStatement(“SELECT * FROM TEST”);
ResultSet rs = stm.executeQuery();
while(rs.next()){
System.out.println(rs.getString(“NAME”));
}
} catch (SQLException ex) {
Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
}
}
}[/code]
segue o teste que faço