I'm trying to create a database with java jdbc
with a method so i'm passing the name type string
of database as argument to database but i'm facing an issue which is You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Algebra'' at line 1
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class DbTest {
private Connection connection;
public void createDb(String name) throws SQLException {
connection = DriverManager.getConnection
("jdbc:mysql://localhost/?user=root&password=root");
String createDbSql = "CREATE DATABASE IF NOT EXISTS ?";
PreparedStatement createDbStat = connection.prepareStatement(createDbSql);
createDbStat.setString(1,name);
createDbStat.executeUpdate();
}
DbTest() {
try {
createDb("Algebra");
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new DbTest();
}
}