2nd Mini Project
2nd Mini Project
methods:===========================================================================
==========
package com.fresco.jdbc.code;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.fresco.jdbc.code.util.DbUtil;
return null;
}
public ResultSet getAllSubjects() throws SQLException {
PreparedStatement ps=con.prepareStatement("select * from subject");
ResultSet rs=ps.executeQuery();
return rs;
}
public boolean insertStudent(String student_name, float score, String name)
throws SQLException {
int id = 0;
if(rs.next())
{
id= rs.getInt(1);
}
else
return false;
ps.setString(1, student_name);
ps.setFloat(2, score);
ps.setInt(3,id);
int i = ps.executeUpdate();
if(i>0)
return true;
return false;
}
public ArrayList getStudentyId(int id) throws SQLException {
PreparedStatement ps=con.prepareStatement("select * from student where
id=?");
ps.setInt(1, id);
ResultSet rs=ps.executeQuery();
ArrayList list = new ArrayList();
while(rs.next())
{
list.add(rs.getInt(1));
list.add(rs.getString(2));
list.add(rs.getFloat(3));
list.add(rs.getInt(4));
}
if(!list.isEmpty())
return list;
return null;
}
public ResultSet getAllStudents() throws SQLException {
}
running script:====================================================================
import com.fresco.jdbc.code.util.DbUtil;
public class RunningScripts {
public void runDbScript() throws Exception {
Connection con = DbUtil.getConnection();
ScriptRunner sr = new ScriptRunner(con);
Reader reader = new BufferedReader(new FileReader("db.sql"));
sr.runScript(reader);
}
}
2:
SQL Query:
SELECT country.name,car_model.name,sum(car_model.price*sales.quantity) as
total_sales from sales as sales
inner join country as country on country.id=sales.country_id
inner join car_model as car_model on car_model.id=sales.model_id
where sales.sales_date like "%/%/2020"
group by country.name, car_model.name
order by total_sales asc;