mysql - java.sql.SQLException: No database selected -
mysql - java.sql.SQLException: No database selected -
as above have problem "select database"
i using xampp, there created database in mysql , named "employees"
this java code:
public static void main(string[] args) { connection conn = null; statement stmt = null; try{ //step 2: register jdbc driver class.forname("com.mysql.jdbc.driver"); //step 3: open connection system.out.println("connecting database..."); conn = drivermanager.getconnection("jdbc:mysql://localhost?user=root&password="); //step 4: execute query system.out.println("creating statement..."); stmt = conn.createstatement(); string sql; sql = "select id, first, last, age employees"; resultset rs = stmt.executequery(sql);
as seen in 'sql' seek reach database, using from employees
i new programming databases. need find path of database? how , can find it?
change connection string create connect right database on localhost
conn = drivermanager.getconnection("jdbc:mysql://localhost/employees?user=root&password=");
alternatively can specify "full" path tables, i.e. database.tablename
:
sql = "select id, first, last, age employees.employees";
java mysql database jdbc
Comments
Post a Comment