Results 1 to 2 of 2
- 03-24-2012, 07:48 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 7
- Rep Power
- 0
how to get input from console using scanner and store it in database(eg:msaccess)
i did a program to directly assignin values and storing to the dattabase n sql queries too...
now i want to noe
1)how to get the input frm console and store it in database
2)how to read the data from a file and then store in a database
Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication6; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; /** * * @author Admin */ public class JavaApplication6 { /** * @param args the command line arguments */ private static final String USERNAME = "admin"; private static final String PASSWORD = "welcome"; private static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver"; private static final String URL ="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=E:\\stud.mdb;}"; public static void main(String[] args) throws ClassNotFoundException, SQLException { String nam="janet",addre="hennur",m1="95",m2="96"; int tot=Integer.parseInt(m1)+Integer.parseInt(m2); Connection connection = null; try { Class.forName(DRIVER); connection = DriverManager.getConnection(URL); Statement stm=connection.createStatement(); stm.executeUpdate("Insert into information(name,address,m1,m2,total)values('"+nam+"','"+addre+"',"+m1+","+m2+","+tot+")"); } catch (SQLException e) { } finally { connection.close(); } } }
- 03-24-2012, 09:06 AM #2
Re: how to get input from console using scanner and store it in database(eg:msaccess)
For reading input from console you can use java.util.Scanner class as:
java.util.Scanner scanner = new Scanner(System.in);
String str = scanner.next();
For storing it in database use the JDBC-ODBC driver to connect and use java.sql package...
create the connection and Statement to execute query.
Best of luck...
Similar Threads
-
Getting input from 3 input text boxes and store into 1 values
By niksipandit in forum New To JavaReplies: 1Last Post: 11-14-2011, 01:03 PM -
Using Scanner console for Graphics
By bensewards in forum New To JavaReplies: 3Last Post: 03-17-2010, 02:16 AM -
Simple DATABASE FROM MSACCESS But ERROR!!!!!!!!
By Elshan0011 in forum New To JavaReplies: 2Last Post: 12-15-2009, 06:46 PM -
How do you write a Java object to MSAccess database?
By rjstanley in forum JDBCReplies: 2Last Post: 10-11-2009, 12:31 PM -
Read from console (Scanner Class)
By hey in forum New To JavaReplies: 10Last Post: 12-11-2007, 10:11 PM
Bookmarks