Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void writeText()
- {
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- final String DB_URL ="jdbc:mysql://mis-sql.uhcl.edu/gattupalliv3940";
- Connection conn = null;
- Statement stat = null;
- ResultSet rs = null;
- try
- {
- conn = DriverManager.getConnection(DB_URL,"gattupalliv3940","1552688");
- stat = conn.createStatement();
- rs = stat.executeQuery("select * from student_2");
- FileWriter fw = new FileWriter("data.txt");
- BufferedWriter bw = new BufferedWriter(fw);
- String line ="";
- while(rs.next())
- {
- line = rs.getInt(1)+"t"+rs.getString(2)+"t"+rs.getDouble(3);
- bw.write(line);
- bw.newLine();
- }
- bw.close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- conn.close();
- rs.close();
- stat.close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- @RequestMapping(value="/")
- public ModelAndView test(HttpServletRequest request, HttpServletResponse response) throws IOException{
- writeText(request.getRealPath("data.txt"));
- return new ModelAndView("home");
- }
- public void writeText(String path) {
- BufferedWriter bw = null;
- try {
- FileWriter fw = new FileWriter(path);
- bw = new BufferedWriter(fw);
- String line = "this is only a test";
- bw.write(line);
- bw.newLine();
- }
- catch(Exception e) {
- e.printStackTrace();
- } finally {
- if( bw != null ) {
- try {
- bw.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement