Ich habe in einem Projekt die beiden folgenden Testklassen
funktioniert einwandfrei
wirft mir die Fehlermeldungen
aus Spring3 habe ich auch alle JARs eingebunden u.a.
org.springframework.core-3.0.0.RELEASE.jar
org.springframework.jdbc-3.0.0.RELEASE.jar
und beide Testklassen verwenden
mysql-connector-java-5.1.19-bin.jar
Danke für eure Hilfe
Code:
package com.proconf.test.db.jdbc.select;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection con = null;
try {
con = DriverManager.getConnection( "jdbc:mysql://localhost/proconf", "root", "");
java.sql.Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM component");
while ( rs.next() )
System.out.printf( "%s, %s %s %s %n", rs.getString(1),
rs.getString(2), rs.getString(3), rs.getString(4) );
rs.close();
} catch ( SQLException e ) {
e.printStackTrace();
} finally {
if ( con != null )
try { con.close(); } catch ( SQLException e ) { e.printStackTrace(); }
}
}
}
funktioniert einwandfrei
Code:
package com.proconf.test.spring.dao.jdbctemplate;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
public class JdbcTemplateTest {
public static void main(String[] args) {
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setUsername("root");
ds.setPassword("");
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUrl("jdbc:mysql://localhost/proconf");
JdbcTemplate jdbc = new JdbcTemplate( ds );
jdbc.query("SELECT name FROM adresse", new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
while (rs.next())
System.out.printf( "%s, %s %s %s %n", rs.getString(1),
rs.getString(2), rs.getString(3), rs.getString(4) );
return null;
}
});
}
}
wirft mir die Fehlermeldungen
Code:
Mai 11, 2012 1:19:42 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
Information: Loaded JDBC driver: com.mysql.jdbc.Driver
Mai 11, 2012 1:19:42 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
Information: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
Mai 11, 2012 1:19:42 PM org.springframework.jdbc.support.SQLErrorCodesFactory <init>
Information: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [SELECT name FROM adresse]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'proconf.adresse' doesn't exist
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:406)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:455)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:463)
at com.proconf.test.spring.dao.jdbctemplate.JdbcTemplateTest.main(JdbcTemplateTest.java:21)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'proconf.adresse' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
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:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4098)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4030)
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:2671)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2621)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1557)
at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:440)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:395)
... 3 more
aus Spring3 habe ich auch alle JARs eingebunden u.a.
org.springframework.core-3.0.0.RELEASE.jar
org.springframework.jdbc-3.0.0.RELEASE.jar
und beide Testklassen verwenden
mysql-connector-java-5.1.19-bin.jar
Danke für eure Hilfe