Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jdbc_test;
- import java.sql.*;
- import java.util.Scanner;
- /**
- *
- * @author hp-admin
- */
- public class JDBC_Test
- {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- // TODO code application logic here
- String tableName=null;
- Scanner input = new Scanner(System.in);
- int id=8;
- System.out.println("Enter the table name: ");
- tableName = input.nextLine();
- try
- {
- //step1 load the driver class
- // Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection con = DriverManager.getConnection(
- "jdbc:oracle:thin:@localhost:1521:oracle12c", "system", "oracle12c");
- Statement stmt = con.createStatement();
- // ResultSet rs = stmt.executeQuery("select * from "+tableName+"where id='"+id+"'");
- ResultSet rs = stmt.executeQuery("select * from "+tableName+"where id='"+id+"'");
- System.out.printf("%15s%15s","Name","ID");
- while (rs.next())
- {
- // System.out.println(rs.getString(1) + " " + rs.getString(2));
- // System.out.printf("n%15s%15S",rs.getString("name"),rs.getString("id"));
- System.out.printf("n%15s",rs.getString("name"));//,rs.getString("id"));
- }
- con.close();
- stmt.close();
- }
- catch (Exception e)
- {
- System.out.println(e);
- }
- }
- }
- Enter the table name:
- t
- java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement