File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes insert into spesific database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "insert into spesific database" Watch "insert into spesific database" New topic

insert into spesific database

sajeevi bangamuwage

Joined: Jan 19, 2005
Posts: 21
Hi all,

i have successfully connect to my SQL server.I have create tables,Insert values and also select all values & server is working properly.
but i cant find where those tables r in my server.also i have created a Database in my server & i want to add those tables into that DB.How can i write codings to do now i write my program.


Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://;user=stromme;password=stromme");
Statement stmt=conn.createStatement( );

String qry="create table studentMS(stdno varchar(32),marks1 integer,marks2 integer);";
String qryi1="insert into studentMS(stdno,marks1,marks2) Values('Madhuranga',86,97);";
int no1=stmt.executeUpdate(qry);
int no2=stmt.executeUpdate(qryi1);

String qry2="select * from studentMS;";
ResultSet rs=stmt.executeQuery(qry2);

String s=rs.getString("stdno");
int i1=rs.getInt("marks1");
int i2=rs.getInt("marks2");
System.out.println(s+" "+i1+" "+i2);
catch(Exception ex){
System.err.println("SQLException: " + ex.getMessage());

Thank you.
Sajeevi Bangamuwage.(SCJP)
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Configure your driver to connect to specific database or use "USE DBNAME"

SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
sajeevi bangamuwage

Joined: Jan 19, 2005
Posts: 21

Thank you very much. i get the answer.

I agree. Here's the link:
subject: insert into spesific database
jQuery in Action, 3rd edition