I want to connect to a database that is created on WAMP. It is a SQL database that I created using SQL Buddy on WAMP.
When I run the code it showed
SEVERE: javax.naming.NameAlreadyBoundException: Use rebind to override
I found out I should use the asadmin command to disbale the JNDI naming on glassfish which worked once but again it showed the same error.
public Connection DbConnection(){
Connection con = null;
DataSource ds = new DataSource();
ds.setDatabaseName("mydatabase");
ds.setDescription("Authorization");
Context ctx = new InitialContext();
ctx.bind("jdbc/mydatabase", ds);
ds.getConnection("root", "");
return con;
}
public void myStatement(){
PreparedStatement pst;
Connection conn = DbConnection();
conn.setAutoCommit(false);
pst = conn.prepareStatement("Select *" +
" from Member WHERE Username = ? ");
pst.setString(1, username);
conn.commit();
pst.close();
}