No Database Selected Error In Java
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About java.sql.sqlexception: no database selected hibernate Us Learn more about Stack Overflow the company Business Learn more about hiring java.sql.sqlexception no database selected glassfish mysql developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the
No Database Selected Mysql Error
Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up java.sql.SQLException: No database selected up vote
Eclipselink Java.sql.sqlexception No Database Selected
1 down vote favorite as above i have a problem to "select the database" i am using xampp, there i created a database in MySQL and named it "employees" This is my 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 a connection System.out.println("Connecting to database..."); conn = DriverManager.getConnection("jdbc:mysql://localhost?user=root&password="); error no database selected hibernate //STEP 4: Execute a query System.out.println("Creating statement..."); stmt = conn.createStatement(); String sql; sql = "SELECT id, first, last, age FROM employees"; ResultSet rs = stmt.executeQuery(sql); As seen in 'sql' I try to reach the database, using FROM employees I am new to programming with databases. Do i need to find the path of the database? how and where can i find it? java mysql database jdbc share|improve this question edited Oct 21 '14 at 21:20 Mureinik 103k2054103 asked Oct 21 '14 at 21:11 user3352472 3917 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted Change your connection string to make it connect to the right database on localhost conn = DriverManager.getConnection("jdbc:mysql://localhost/employees?user=root&password="); Alternatively you can specify the "full" path to the tables, i.e. database.tablename: sql = "SELECT id, first, last, age FROM employees.employees"; share|improve this answer edited Oct 21 '14 at 21:22 answered Oct 21 '14 at 21:16 MrTux 10.4k102559 add a comment| up vote 1 down vote You need to specify the database you want to use in the connection string: conn = DriverManager.getConnection("jdbc:mysql://localhost/employees?user=root&password="); share|improve this answer answered Oct 21 '14 at 21:16 Mureinik 103k2054103 add a comment| Your Ans
Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums Forum: JDBC and Relational Databases No database selected
Spring Boot No Database Selected
error in jdbc for mysql application Radhakrishna Sharma Gorenta Ranch create database mysql Hand Posts: 63 I like... posted 5 years ago import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class JdbcMySql { public static void main(String[] args) throws Exception { // Load the JDBC-ODBC bridge driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Connect to the database Connection con = DriverManager.getConnection("jdbc:odbc:radha", "root", http://stackoverflow.com/questions/26496408/java-sql-sqlexception-no-database-selected "sharma"); Statement stmt = con.createStatement(); ResultSet rs=stmt.executeQuery("select * from employee"); while(rs.next()) { System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getFloat(3)); } } } and the error is "No database selected" very simple application how to resolve this one...please help me Paul Clapham Sheriff Posts: 21443 33 I like... posted 5 years ago That means that you haven't selected a database, like it https://coderanch.com/t/543047/JDBC/databases/database-selected-error-jdbc-mysql says. But the selection of the database would be somewhere in the ODBC configuration, so showing us Java code isn't actually of any use. So either fix your ODBC configuration to select a database, or (a better option) stop using ODBC and use the MySQL JDBC driver. Jan Cumps Bartender Posts: 2605 14 I like... posted 5 years ago Welcome to the Ranch, Radhakrishna. While you are learning to connect to MySQL, can I point you to the MySQL jdbc driver in stead of the odbc bridge driver, as Paul advised? OCUP UML fundamental and ITIL foundation Radhakrishna Sharma Gorenta Ranch Hand Posts: 63 I like... posted 5 years ago Thank you paul. for your reply. i already created odbc DSN for MySql. what would be the actual error,please suggest me. and please tell me that how to use type4 MySql driver? Regards, Radhakrishna Post Reply Bookmark Topic Watch Topic New Topic Similar Threads Unable to inject @Resource into ApplicationClient using ACC Adding components dynamically Need to pass
details. Win a copy of Penetration Testing Basics this week in the Security forum! Post Reply Bookmark Topic Watch Topic no database New Topic programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums Forum: GlassFish What is causing no database selected this "No database selected" error in my Glassfish/MySQL configuration? John Mallonee Greenhorn Posts: 1 posted 2 years ago Here is the error: org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: No database selected Error Code: 1046 Here is the glassfish-resources.xml: