wood burning stoves 2.0*
The moose likes JDBC 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
Bookmark "insert into spesific database" Watch "insert into spesific database" New topic
Author

insert into spesific database

sajeevi bangamuwage
Greenhorn

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 & display.my 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 that.here now i write my program.

try{

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.114:1433;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);
while(rs.next()){

String s=rs.getString("stdno");
int i1=rs.getInt("marks1");
int i2=rs.getInt("marks2");
System.out.println(s+" "+i1+" "+i2);
}
conn.close();
}
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
Greenhorn

Joined: Jan 19, 2005
Posts: 21


Thank you very much. i get the answer.

Sajeevi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: insert into spesific database