我有一个mysql数据库,我想连接到我的java(springmvc)项目(我正在使用intellij)。据我所知,我在intellij中定义的实体和存储库相当于数据库的表。但是,我编写了一个简短的代码,可以连接到我的datatbase,运行sql查询并保存/打印查询结果:
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver"); // Connecting to mySql
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/theprocess?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC","root","root");
// Connecting to our database
Statement stmt = con.createStatement();
// Object that allows executing SQL queries
ResultSet rs = stmt.executeQuery("select * from clients");
// Storing the query's result
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
// Defines which columns to print
con.close(); // Closing the connection;
}catch(Exception e){ System.out.println(e);}
}
所以我的问题是,如果我有代码,我是否需要实体和存储库?感谢您的帮助:)
暂无答案!
目前还没有任何答案,快来回答吧!