---
title: "MySQLSyntaxErrorException"  
description: "MySQLSyntaxErrorException"  
author: "Anonymous User"  
published: 2013-06-12  
updated: 2013-06-12  
canonical: https://www.mindstick.com/forum/1046/mysqlsyntaxerrorexception  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# MySQLSyntaxErrorException

I've just started to learn [MySQL](https://www.mindstick.com/articles/12156/what-is-mysql) and JDBC.

I created a [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) called testdb using phpmyadmin. Table just has 2 columns called first and last. When I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [connect](https://www.mindstick.com/articles/12810/how-to-connect-tablet-to-external-monitor-or-flat-screen-tv-using-computer-adapters) the [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) from my [java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp), I get MySQLSyntaxError. However I could not [figure](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) it out.

Here is my class:

```
import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException; public class Main {     public static void main(String[] args) throws ClassNotFoundException, SQLException {        String url = "jdbc:mysql://localhost:3306/testdb";         //Accessing driver from the JAR file.        Class.forName("com.mysql.jdbc.Driver");         //Creating a variable for the connection "con"        Connection con = DriverManager.getConnection(url,"root","password");         //Here is the query        PreparedStatement statement = con.prepareStatement("select * from name");         //Execute query        ResultSet result = statement.executeQuery();         while(result.next()) {            System.out.println(result.getString(1) + " " + result.getString(2));        }      } }
```

\

## And here is the [exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling):

```
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'testdb.name' doesn't exist    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)    at com.mysql.jdbc.Util.getInstance(Util.java:386)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)    at Main.main(Main.java:22)
```

\

Thank you for your help

## Replies

### Reply by Vijay Shukla

Hey Ashish Pandey!\
\
You've created a table named testdb therefore your query should be\
select * from testdb \
not select * from name\
you should really check your stacktraces.\


---

Original Source: https://www.mindstick.com/forum/1046/mysqlsyntaxerrorexception

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
